You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: agent-framework/migration-guide/from-autogen/index.md
+34-25Lines changed: 34 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -221,33 +221,39 @@ def get_time() -> str:
221
221
client = OpenAIChatClient(model_id="gpt-5")
222
222
223
223
asyncdefexample():
224
-
# Direct creation
224
+
# Direct creation with default options
225
225
agent = ChatAgent(
226
226
name="assistant",
227
227
chat_client=client,
228
228
instructions="You are a helpful assistant.",
229
-
tools=[get_weather] # Multi-turn by default
229
+
tools=[get_weather], # Multi-turn by default
230
+
default_options={
231
+
"temperature": 0.7,
232
+
"max_tokens": 1000,
233
+
}
230
234
)
231
235
232
236
# Factory method (more convenient)
233
237
agent = client.create_agent(
234
238
name="assistant",
235
239
instructions="You are a helpful assistant.",
236
-
tools=[get_weather]
240
+
tools=[get_weather],
241
+
default_options={"temperature": 0.7}
237
242
)
238
243
239
-
# Execution with runtime tool configuration
244
+
# Execution with runtime tool and options configuration
240
245
result =await agent.run(
241
246
"What's the weather?",
242
-
tools=[get_time], # Can add tools at runtime
243
-
tool_choice="auto"
247
+
tools=[get_time], # Can add tools at runtime (keyword arg)
248
+
options={"tool_choice": "auto"} # Other options go in options dict
244
249
)
245
250
```
246
251
247
252
**Key Differences:**
248
253
249
254
-**Default behavior**: `ChatAgent` automatically iterates through tool calls, while `AssistantAgent` requires explicit `max_tool_iterations` setting
250
-
-**Runtime configuration**: `ChatAgent.run()` accepts `tools` and `tool_choice` parameters for per-invocation customization
255
+
-**Runtime configuration**: `ChatAgent.run()` accepts `tools` as a keyword argument and other options via the `options` dict parameter for per-invocation customization
256
+
-**Options system**: Agent Framework uses TypedDict-based options (e.g., `OpenAIChatOptions`) for type safety and IDE autocomplete. Options are passed via `default_options` at construction and `options` at runtime
-**State management**: `ChatAgent` is stateless and doesn't maintain conversation history between invocations, unlike `AssistantAgent` which maintains conversation history as part of its state
253
259
@@ -340,18 +346,21 @@ async for event in agent.run_stream(task="Hello"):
340
346
```python
341
347
# Assume we have client, agent, and tools from previous examples
342
348
asyncdefstreaming_example():
343
-
# Chat client streaming
344
-
asyncfor chunk in client.get_streaming_response("Hello", tools=tools):
349
+
# Chat client streaming - tools go in options dict
350
+
asyncfor chunk in client.get_streaming_response(
351
+
"Hello",
352
+
options={"tools": tools}
353
+
):
345
354
if chunk.text:
346
355
print(chunk.text, end="")
347
356
348
-
# Agent streaming
349
-
asyncfor chunk in agent.run_stream("Hello"):
357
+
# Agent streaming - tools can be keyword arg on agents
358
+
asyncfor chunk in agent.run_stream("Hello", tools=tools):
350
359
if chunk.text:
351
360
print(chunk.text, end="", flush=True)
352
361
```
353
362
354
-
Tip: In Agent Framework, both clients and agents yield the same update shape; you can read `chunk.text` in either case.
363
+
Tip: In Agent Framework, both clients and agents yield the same update shape; you can read `chunk.text` in either case. Note that for chat clients, `tools` goes in the `options` dict, while for agents, `tools` remains a direct keyword argument.
355
364
356
365
### Message Types and Creation
357
366
@@ -688,8 +697,8 @@ Notes:
688
697
from collections.abc import AsyncIterable
689
698
from typing import Any
690
699
from agent_framework import (
691
-
AgentRunResponse,
692
-
AgentRunResponseUpdate,
700
+
AgentResponse,
701
+
AgentResponseUpdate,
693
702
AgentThread,
694
703
BaseAgent,
695
704
ChatMessage,
@@ -704,7 +713,7 @@ class StaticAgent(BaseAgent):
704
713
*,
705
714
thread: AgentThread |None=None,
706
715
**kwargs: Any,
707
-
) -> AgentRunResponse:
716
+
) -> AgentResponse:
708
717
# Build a static reply
709
718
reply = ChatMessage(role=Role.ASSISTANT, contents=[TextContent(text="Hello from AF custom agent")])
710
719
@@ -713,17 +722,17 @@ class StaticAgent(BaseAgent):
0 commit comments