Skip to content

Commit a8a090f

Browse files
authored
Merge branch 'main' into fix-openai-conversation-session
2 parents 2e48735 + 1f705d5 commit a8a090f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4396
-114
lines changed

.github/workflows/update-docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on:
1919
- mkdocs.yml
2020
- '!docs/ja/**'
2121
- '!docs/ko/**'
22+
- '!docs/zh/**'
2223

2324
permissions:
2425
contents: write

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ celerybeat.pid
103103
.python-version
104104
.env*
105105
.venv
106+
.venv*
106107
env/
107108
venv/
108109
ENV/

docs/context.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,51 @@ if __name__ == "__main__":
6868
4. The context is passed to the `run` function.
6969
5. The agent correctly calls the tool and gets the age.
7070

71+
---
72+
73+
### Advanced: `ToolContext`
74+
75+
In some cases, you might want to access extra metadata about the tool being executed — such as its name, call ID, or raw argument string.
76+
For this, you can use the [`ToolContext`][agents.tool_context.ToolContext] class, which extends `RunContextWrapper`.
77+
78+
```python
79+
from typing import Annotated
80+
from pydantic import BaseModel, Field
81+
from agents import Agent, Runner, function_tool
82+
from agents.tool_context import ToolContext
83+
84+
class WeatherContext(BaseModel):
85+
user_id: str
86+
87+
class Weather(BaseModel):
88+
city: str = Field(description="The city name")
89+
temperature_range: str = Field(description="The temperature range in Celsius")
90+
conditions: str = Field(description="The weather conditions")
91+
92+
@function_tool
93+
def get_weather(ctx: ToolContext[WeatherContext], city: Annotated[str, "The city to get the weather for"]) -> Weather:
94+
print(f"[debug] Tool context: (name: {ctx.tool_name}, call_id: {ctx.tool_call_id}, args: {ctx.tool_arguments})")
95+
return Weather(city=city, temperature_range="14-20C", conditions="Sunny with wind.")
96+
97+
agent = Agent(
98+
name="Weather Agent",
99+
instructions="You are a helpful agent that can tell the weather of a given city.",
100+
tools=[get_weather],
101+
)
102+
```
103+
104+
`ToolContext` provides the same `.context` property as `RunContextWrapper`,
105+
plus additional fields specific to the current tool call:
106+
107+
- `tool_name` – the name of the tool being invoked
108+
- `tool_call_id` – a unique identifier for this tool call
109+
- `tool_arguments` – the raw argument string passed to the tool
110+
111+
Use `ToolContext` when you need tool-level metadata during execution.
112+
For general context sharing between agents and tools, `RunContextWrapper` remains sufficient.
113+
114+
---
115+
71116
## Agent/LLM context
72117

73118
When an LLM is called, the **only** data it can see is from the conversation history. This means that if you want to make some new data available to the LLM, you must do it in a way that makes it available in that history. There are a few ways to do this:

docs/scripts/translate_docs.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
languages = {
2828
"ja": "Japanese",
2929
"ko": "Korean",
30+
"zh": "Chinese",
3031
# Add more languages here, e.g., "fr": "French"
3132
}
3233

@@ -114,6 +115,30 @@
114115
"Build your first agent in minutes.": "단 몇 분 만에 첫 에이전트를 만들 수 있습니다",
115116
"Let's build": "시작하기",
116117
},
118+
"zh": {
119+
"agents": "智能体",
120+
"computer use": "计算机操作",
121+
"OAI hosted tools": "由OpenAI托管的工具",
122+
"well formed data": "格式良好的数据",
123+
"guardrail": "安全防护措施",
124+
"handoffs": "任务转移",
125+
"function tools": "工具调用",
126+
"tracing": "追踪",
127+
"code examples": "代码示例",
128+
"vector store": "向量存储",
129+
"deep research": "深度研究",
130+
"category": "目录",
131+
"user": "用户",
132+
"parameter": "参数",
133+
"processor": "进程",
134+
"server": "服务",
135+
"web search": "网络检索",
136+
"file search": "文件检索",
137+
"streaming": "流式传输",
138+
"system prompt": "系统提示词",
139+
"Python first": "Python 优先",
140+
# Add more mappings here
141+
},
117142
# Add more languages here
118143
}
119144
eng_to_non_eng_instructions = {
@@ -136,6 +161,13 @@
136161
"* 'instructions', 'tools' 같은 API 매개변수와 temperature, top_p, max_tokens, presence_penalty, frequency_penalty 등은 영문 그대로 유지하세요.",
137162
"* 문장이 아닌 불릿 항목 끝에는 마침표를 찍지 마세요.",
138163
],
164+
"zh": [
165+
"* The term 'examples' must be code examples when the page mentions the code examples in the repo, it can be translated as either 'code examples' or 'sample code'.",
166+
"* The term 'primitives' can be translated as basic components.",
167+
"* When the terms 'instructions' and 'tools' are mentioned as API parameter names, they must be kept as is.",
168+
"* The terms 'temperature', 'top_p', 'max_tokens', 'presence_penalty', 'frequency_penalty' as parameter names must be kept as is.",
169+
"* Keep the original structure like `* **The thing**: foo`; this needs to be translated as `* **(translation)**: (translation)`",
170+
],
139171
# Add more languages here
140172
}
141173

0 commit comments

Comments
 (0)