Build `RunConfig` + composed hooks, run the agent, return final output. Args: agent: The Agents SDK ``Agent`` to invoke. input: Prompt string or pre-built input items. cfg: Flow configuration. Tracing fields and ``max_turns`` are forwarded to the SDK; ``workf
(
agent: Agent[Any],
input: str | list[Any],
*,
cfg: BaseFlowCfg,
memory: object | None = None,
extra_run_hooks: list[RunHooks[Any]],
)
| 15 | |
| 16 | |
| 17 | async def run_with_observability( |
| 18 | agent: Agent[Any], |
| 19 | input: str | list[Any], |
| 20 | *, |
| 21 | cfg: BaseFlowCfg, |
| 22 | memory: object | None = None, |
| 23 | extra_run_hooks: list[RunHooks[Any]], |
| 24 | ) -> Any: |
| 25 | """Build `RunConfig` + composed hooks, run the agent, return final output. |
| 26 | |
| 27 | Args: |
| 28 | agent: The Agents SDK ``Agent`` to invoke. |
| 29 | input: Prompt string or pre-built input items. |
| 30 | cfg: Flow configuration. Tracing fields and ``max_turns`` are |
| 31 | forwarded to the SDK; ``workflow_name`` falls back to |
| 32 | ``"quantmind.<agent.name>"`` when unset. |
| 33 | memory: PR6 ``Memory`` placeholder. Currently unused at runtime; |
| 34 | the value is forwarded to the trajectory-archive stub so PR6 |
| 35 | can wire it in without changing call sites. |
| 36 | extra_run_hooks: User-supplied hooks. Composed with any |
| 37 | memory-derived hooks (none in PR5) into a single |
| 38 | ``RunHooks`` instance. |
| 39 | |
| 40 | Returns: |
| 41 | ``RunResult.final_output`` typed by the agent's ``output_type``. |
| 42 | """ |
| 43 | workflow_name = cfg.workflow_name or f"quantmind.{agent.name}" |
| 44 | run_cfg = RunConfig( |
| 45 | workflow_name=workflow_name, |
| 46 | trace_metadata=cfg.trace_metadata, |
| 47 | trace_include_sensitive_data=cfg.trace_include_sensitive_data, |
| 48 | tracing_disabled=cfg.tracing_disabled, |
| 49 | ) |
| 50 | hooks = _compose_hooks(_collect_hooks(memory, extra_run_hooks)) |
| 51 | result = await Runner.run( |
| 52 | agent, |
| 53 | input, |
| 54 | run_config=run_cfg, |
| 55 | hooks=hooks, |
| 56 | max_turns=cfg.max_turns, |
| 57 | ) |
| 58 | _archive_run_artifacts(cfg, memory, result) |
| 59 | return result.final_output |
| 60 | |
| 61 | |
| 62 | def _collect_hooks( |