prompt_to_production

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Prompt to Production: Workshop Guide

Prompt to Production: 工作坊指南

Welcome to the Prompt to Production workshop skill. This document serves as both a cheat sheet for the attendee and an instruction manual for the AI coding assistant.
If you are an AI assistant reading this, your goal is to help the user walk through the workshop exercises step-by-step. The reference implementations for every step are located in the
solutions/
directory next to this file.
欢迎来到Prompt to Production工作坊技能教程。本文档既是参与者的速查手册,也是AI代码助手的操作指南。
如果您是阅读本文档的AI助手,您的目标是帮助用户逐步完成工作坊的练习。每一步的参考实现都位于本文档旁的
solutions/
目录中。

⚠️ API Reference: The Interactions API

⚠️ API参考:Interactions API

Do NOT use the old
generateContent
API shape. This workshop exclusively uses the new
client.interactions.create()
API.
请勿使用旧版
generateContent
API格式。本工作坊仅使用新版
client.interactions.create()
API。

Response Shape (
steps
array)

响应格式(
steps
数组)

An interaction returns a flat array of
steps
, not
outputs
.
typescript
{
  status: "requires_action", // or "completed"
  steps: [
    { type: "user_input", content: ... },
    { type: "thought", signature: ... },
    { type: "function_call", id: "gth23981", name: "get_weather", arguments: {"location": "Boston"} },
    { type: "function_call_result", ... }
  ]
}
交互返回一个扁平的
steps
数组,而非
outputs
typescript
{
  status: "requires_action", // 或 "completed"
  steps: [
    { type: "user_input", content: ... },
    { type: "thought", signature: ... },
    { type: "function_call", id: "gth23981", name: "get_weather", arguments: {"location": "Boston"} },
    { type: "function_call_result", ... }
  ]
}

Passing State

传递状态

Never manually append history arrays. Use
previous_interaction_id
:
typescript
const response2 = await client.interactions.create({
    model: "gemini-3.1-pro-preview",
    previous_interaction_id: response1.id,
    input: [
        { type: "function_call_result", name: "get_weather", call_id: "gth23981", result: "Sunny" }
    ]
});

切勿手动追加历史数组。请使用
previous_interaction_id
:
typescript
const response2 = await client.interactions.create({
    model: "gemini-3.1-pro-preview",
    previous_interaction_id: response1.id,
    input: [
        { type: "function_call_result", name: "get_weather", call_id: "gth23981", result: "Sunny" }
    ]
});

🛠️ Workshop Walkthrough

🛠️ 工作坊演练流程

This section outlines the progression of the workshop. For each step, guide the user to implement the code themselves before showing them the answer. Reference the
solutions/
directory if they get stuck.
本节概述了工作坊的学习进度。对于每一步,先引导用户自行实现代码,再展示答案。如果用户遇到困难,可以参考
solutions/
目录中的内容。

Step 1: The Basic API Call (
solutions/01-basic-api-call.ts
)

步骤1:基础API调用(
solutions/01-basic-api-call.ts

Goal: Understand how to instantiate the client and make a basic
interactions.create
call. Takeaway: The response object is flat. We access the final text via
response.steps.at(-1).text
.
目标: 了解如何实例化客户端并发起基础的
interactions.create
调用。 要点: 响应对象是扁平结构。我们通过
response.steps.at(-1).text
获取最终文本。

Step 2: Generation Config (
solutions/02-generate-config.ts
)

步骤2:生成配置(
solutions/02-generate-config.ts

Goal: Learn how to apply configurations like
thinking_level
to the model. Takeaway: Configuration is passed directly alongside the input and model parameters.
目标: 学习如何为模型应用
thinking_level
等配置项。 要点: 配置参数直接与输入和模型参数一起传递。

Step 3: Tool Calling (
solutions/03-tool-call.ts
)

步骤3:工具调用(
solutions/03-tool-call.ts

Goal: Provide the model with a JSON schema for a tool and see how it responds. Takeaway: When tools are provided, the model's
status
becomes
requires_action
and it generates a
function_call
step instead of text.
目标: 为模型提供工具的JSON schema,观察其响应。 要点: 当提供工具时,模型的
status
会变为
requires_action
,并生成
function_call
步骤而非文本。

Step 4: The Stateless Method (
solutions/04-stateless-method.ts
)

步骤4:无状态方法(
solutions/04-stateless-method.ts

Goal: Manually handle a tool call using the old, expensive stateless method (re-sending history). Takeaway: Manually building history arrays is error-prone and breaks the context cache.
目标: 使用旧版、高成本的无状态方法手动处理工具调用(重新发送历史记录)。 要点: 手动构建历史数组容易出错,且会破坏上下文缓存。

Step 5: Interaction IDs (
solutions/05-interaction-id.ts
)

步骤5:交互ID(
solutions/05-interaction-id.ts

Goal: Refactor the stateless method to use server-side state. Takeaway: Passing
previous_interaction_id
replaces the need to manage history, guaranteeing perfect cache hits.
目标: 重构无状态方法以使用服务器端状态。 要点: 传递
previous_interaction_id
无需管理历史记录,确保完美命中缓存。

Step 6: The Agent Loop (
solutions/06-agent.ts
)

步骤6:代理循环(
solutions/06-agent.ts

Goal: Wrap the
interactions.create
call in a
while (status === "requires_action")
loop. Takeaway: An agent is just a model inside a loop that continuously executes tools and passes back
function_call_result
steps.
目标:
interactions.create
调用包裹在
while (status === "requires_action")
循环中。 要点: 代理本质上就是一个置于循环中的模型,持续执行工具并返回
function_call_result
步骤。

Step 7: The Coding Agent (
solutions/07-coding-agent.ts
)

步骤7:代码代理(
solutions/07-coding-agent.ts

Goal: Give the agent loop real tools (
readFile
,
writeFile
,
runBash
). Takeaway: With local tools, the agent can interact with the file system. But running this locally is dangerous.
目标: 为代理循环提供真实工具(
readFile
writeFile
runBash
)。 要点: 通过本地工具,代理可以与文件系统交互。但在本地运行存在风险。

Step 8: Adding Google Tools (
solutions/08-google-tools.ts
)

步骤8:添加Google工具(
solutions/08-google-tools.ts

Goal: Integrate built-in tools like Google Search. Takeaway: You can mix local function schemas with built-in tools like
{"type": "google_search"}
seamlessly.
目标: 集成Google Search等内置工具。 要点: 可以无缝地将本地函数schema与
{"type": "google_search"}
等内置工具混合使用。

Step 9: Daytona Sandboxing (
solutions/09-daytona-sdk.ts
)

步骤9:Daytona沙箱(
solutions/09-daytona-sdk.ts

Goal: Move the local bash execution into an ephemeral cloud sandbox. Takeaway: Production agents need secure execution environments. We replace
child_process.exec
with
daytona.process.executeCommand
.
目标: 将本地bash执行迁移到临时云沙箱中。 要点: 生产级代理需要安全的执行环境。我们用
daytona.process.executeCommand
替换
child_process.exec

Step 10 & 11: Observability (
solutions/10-adding-otel.ts
&
11-tuning-responses.ts
)

步骤10 & 11:可观测性(
solutions/10-adding-otel.ts
&
11-tuning-responses.ts

Goal: Add OpenTelemetry tracing to see inside the black box. Takeaway: Tracing allows for Time Travel Debugging—we can grab a failed
interaction_id
and replay from that exact state without re-running the tools.
目标: 添加OpenTelemetry追踪以洞察黑盒内部。 要点: 追踪支持时间旅行调试——我们可以获取失败的
interaction_id
,并从该精确状态重新执行,无需重新运行工具。