Processes the output of LlmAgent run as a node.
(agent: Any, ctx: Context, event: Event)
| 251 | |
| 252 | |
| 253 | def process_llm_agent_output(agent: Any, ctx: Context, event: Event) -> None: |
| 254 | """Processes the output of LlmAgent run as a node.""" |
| 255 | if ( |
| 256 | event.get_function_calls() |
| 257 | or event.partial |
| 258 | or not event.content |
| 259 | or event.content.role != 'model' |
| 260 | ): |
| 261 | return |
| 262 | |
| 263 | output = None |
| 264 | text = ( |
| 265 | ''.join(p.text for p in event.content.parts if p.text and not p.thought) |
| 266 | if event.content.parts |
| 267 | else '' |
| 268 | ) |
| 269 | if agent.output_schema: |
| 270 | if text.strip(): |
| 271 | output = validate_schema(agent.output_schema, text) |
| 272 | else: |
| 273 | output = None |
| 274 | else: |
| 275 | output = text |
| 276 | |
| 277 | if agent.output_key and output is not None: |
| 278 | ctx.actions.state_delta[agent.output_key] = output |
| 279 | |
| 280 | event.output = output |
| 281 | event.node_info.message_as_output = True |
| 282 | |
| 283 | |
| 284 | async def run_llm_agent_as_node( |
no test coverage detected