77
77
78
78
79
79
_LOGGER : logging .Logger = logging .getLogger (__name__ )
80
- _LOGGER .setLevel (logging .DEBUG )
81
80
82
81
83
82
@dataclass (repr = False )
@@ -105,12 +104,9 @@ def new_message_id(self) -> str:
105
104
class AdapterAGUI (Generic [AgentDepsT , OutputDataT ]):
106
105
"""An agent adapter providing AG-UI protocol support for PydanticAI agents.
107
106
108
- This class manages the agent runs, tool calls, and provides an adapter
109
- for running agents with Server-Sent Event (SSE) streaming responses using
110
- the AG-UI protocol.
111
-
112
- It supports multiple threads and runs, allowing for concurrent agent
113
- execution and tool calls.
107
+ This class manages the agent runs, tool calls, state storage and providing
108
+ an adapter for running agents with Server-Sent Event (SSE) streaming
109
+ responses using the AG-UI protocol.
114
110
115
111
Example:
116
112
@@ -143,8 +139,8 @@ async def root(input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE
143
139
media_type=SSE_CONTENT_TYPE,
144
140
)
145
141
146
- PydanticAI Tools which return AG-UI events will be sent to the client
147
- as part of the event stream, single events and iterables of events are
142
+ PydanticAI tools which return AG-UI events will be sent to the client
143
+ as part of the event stream, single events and event iterables are
148
144
supported.
149
145
150
146
Examples:
@@ -296,8 +292,9 @@ async def _tool_events(
296
292
Yields:
297
293
AG-UI Server-Sent Events (SSE).
298
294
"""
299
- # TODO(steve): Determine how to handle when we have multiple parts. Currently
300
- # AG-UI only seems to support a single tool call per request.
295
+ # TODO(steve): Determine how to handle multiple parts. Currently
296
+ # AG-UI only supports a single tool call per request, but that
297
+ # may change in the future.
301
298
part : ModelRequestPart
302
299
for part in parts :
303
300
if not isinstance (part , ToolReturnPart ):
@@ -323,9 +320,9 @@ async def _tool_events(
323
320
def _convert_tools (self , run_tools : list [ToolAGUI ]) -> list [Tool [AgentDepsT ]]:
324
321
"""Convert AG-UI tools to PydanticAI tools.
325
322
326
- Creates placeholder Tool objects from AG-UI tool definitions. These tools
327
- don't actually execute anything - they just provide the necessary tool
328
- definitions and names for the PydanticAI agent.
323
+ Creates ` Tool` objects from AG-UI tool definitions. These tools don't
324
+ actually execute anything, that is done by AG-UI client - they just
325
+ provide the necessary tool definitions to PydanticAI agent.
329
326
330
327
Args:
331
328
run_tools: List of AG-UI tool definitions to convert.
@@ -342,7 +339,7 @@ def _tool_call(self, tool: ToolAGUI) -> Tool[AgentDepsT]:
342
339
tool: The AG-UI tool definition to convert.
343
340
344
341
Returns:
345
- A PydanticAI Tool object that calls the AG-UI tool.
342
+ A PydanticAI ` Tool` object that calls the AG-UI tool.
346
343
"""
347
344
348
345
def _tool_stub (* args : Any , ** kwargs : Any ) -> ToolResult :
@@ -352,7 +349,7 @@ def _tool_stub(*args: Any, **kwargs: Any) -> ToolResult:
352
349
Never returns as it always raises an exception.
353
350
354
351
Raises:
355
- UnexpectedToolCallError: Always raised since this is a stub .
352
+ UnexpectedToolCallError: Always raised since this should never be called .
356
353
"""
357
354
raise UnexpectedToolCallError (tool_name = tool .name ) # pragma: no cover
358
355
@@ -521,13 +518,13 @@ async def _handle_agent_event(
521
518
522
519
523
520
def _convert_history (messages : list [Message ]) -> list [ModelMessage ]:
524
- """Convert a list of AG-UI history to a PydanticAI one.
521
+ """Convert a AG-UI history to a PydanticAI one.
525
522
526
523
Args:
527
- messages: List of `ag_ui.Message` to convert.
524
+ messages: List of AG-UI messages to convert.
528
525
529
526
Returns:
530
- List of `ModelMessage` compatible with PydanticAI .
527
+ List of PydanticAI model messages .
531
528
"""
532
529
msg : Message
533
530
result : list [ModelMessage ] = []
0 commit comments