|
33 | 33 |
|
34 | 34 | def _truncate(text: str, max_len: int = 200) -> str: |
35 | 35 | """Truncate long tool output for display.""" |
| 36 | + return text |
36 | 37 | if not isinstance(text, str): |
37 | 38 | text = str(text) |
38 | 39 | if len(text) <= max_len: |
39 | 40 | return text |
40 | 41 | return text[:max_len] + f"\n... (truncated, total {len(text)} chars)" |
41 | 42 |
|
42 | 43 |
|
43 | | -def _print_subagent_progress(payload: dict) -> None: |
44 | | - """Render one forwarded sub-agent execution event. |
45 | | -
|
46 | | - ``payload`` is a :class:`SubAgentProgress` dict: ``author`` / ``partial``, |
47 | | - the framework-native ``content`` dump (``parts`` with ``function_call`` / |
48 | | - ``function_response`` / ``text`` / ``thought``), and optional ``error`` / |
49 | | - ``usage``. Indented under the parent output so the sub-agent's steps are |
50 | | - visually distinct from the orchestrator's. |
51 | | - """ |
52 | | - name = payload.get("author") or "subagent" |
53 | | - # Errors first — always surface them, even on an otherwise-partial event. |
54 | | - err = payload.get("error") |
55 | | - if err: |
56 | | - print(f"\n \U0001F9E9 [{name}] !! error {err.get('code')}: {err.get('message')}") |
57 | | - if payload.get("partial"): |
58 | | - # Skip streaming text deltas to keep the demo output readable; the |
59 | | - # non-partial steps below already summarize the sub-agent's work. |
60 | | - return |
61 | | - parts = (payload.get("content") or {}).get("parts") or [] |
62 | | - has_calls = any(p.get("function_call") or p.get("function_response") for p in parts) |
63 | | - for p in parts: |
64 | | - fc = p.get("function_call") |
65 | | - if fc: |
66 | | - print(f"\n \U0001F9E9 [{name}] -> tool {fc.get('name')}({_truncate(fc.get('args'))})") |
67 | | - fr = p.get("function_response") |
68 | | - if fr: |
69 | | - print(f" \U0001F9E9 [{name}] <- {_truncate(fr.get('response'))}") |
70 | | - text = p.get("text") |
71 | | - if text and not p.get("thought") and not has_calls: |
72 | | - print(f"\n \U0001F9E9 [{name}] {_truncate(text)}") |
73 | | - |
74 | | - |
75 | 44 | _QUERIES = { |
76 | 45 | "minimal": [ |
77 | 46 | # Simple task: orchestrator may call word_count directly. |
@@ -124,18 +93,6 @@ async def run_demo(mode: str): |
124 | 93 | session_id=current_session_id, |
125 | 94 | new_message=user_content, |
126 | 95 | ): |
127 | | - # Forwarded sub-agent execution events (SubAgentConfig |
128 | | - # forward_events=True). These are partial progress events carrying |
129 | | - # the sub-agent's own steps under custom_metadata.payload; they |
130 | | - # never reach the parent LLM's context. This demo registers only the |
131 | | - # sub-agent tool, so tool_progress alone identifies them; an app with |
132 | | - # several progress tools would also branch on meta["tool_name"]. |
133 | | - meta = event.custom_metadata or {} |
134 | | - payload = meta.get("payload") |
135 | | - if meta.get("tool_progress") and isinstance(payload, dict): |
136 | | - _print_subagent_progress(payload) |
137 | | - continue |
138 | | - |
139 | 96 | if event.content and event.content.parts and event.author != "user": |
140 | 97 | if event.partial: |
141 | 98 | for part in event.content.parts: |
|
0 commit comments