forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_rendering_agent.py
More file actions
67 lines (55 loc) · 2.51 KB
/
Copy pathtool_rendering_agent.py
File metadata and controls
67 lines (55 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Tool Rendering agent — backs the three tool-rendering cells.
Mirrors LangGraph's `langgraph-python/src/agents/tool_rendering_agent.py`:
this agent serves
- `tool-rendering` — per-tool + catch-all on frontend
- `tool-rendering-default-catchall` — no frontend renderers
- `tool-rendering-custom-catchall` — wildcard renderer on frontend
All three share this backend; they differ only in how the frontend
renders the same tool calls. The `tool-rendering-reasoning-chain` cell
is intentionally NOT served by this agent — it has its own variant
(`tool_rendering_reasoning_chain_agent.py`) that routes through the
OpenAI Responses API for reasoning streaming. Mixing reasoning events
into the catchall renderers breaks the default-catchall cell's spec
because the built-in default-renderer doesn't paint reasoning blocks.
Tool surface is identical to the reasoning-chain variant — get_weather,
search_flights, get_stock_price, roll_d20 — sourced via direct imports
from that module so the two agents can never drift apart.
"""
from __future__ import annotations
from textwrap import dedent
from agent_framework import Agent, BaseChatClient
from agent_framework_ag_ui import AgentFrameworkAgent
from agents.tool_rendering_reasoning_chain_agent import (
get_stock_price,
get_weather,
roll_d20,
search_flights,
)
SYSTEM_PROMPT = dedent(
"""
You are a travel & lifestyle concierge. Use the mock tools for
weather, flights, stock prices, or d20 rolls when the user asks;
otherwise reply in plain text. For flights, default origin to 'SFO'
if the user only names a destination. Call multiple tools in one
turn if the user asks for them. After tools return, summarize in
one short sentence. Never fabricate data a tool could provide.
"""
).strip()
def create_tool_rendering_agent(chat_client: BaseChatClient) -> AgentFrameworkAgent:
"""Instantiate the tool-rendering agent (non-reasoning)."""
base_agent = Agent(
client=chat_client,
name="tool_rendering_agent",
instructions=SYSTEM_PROMPT,
tools=[get_weather, search_flights, get_stock_price, roll_d20],
)
return AgentFrameworkAgent(
agent=base_agent,
name="ToolRenderingAgent",
description=(
"Weather + flights + stocks + d20 mock tools, multi-tool per "
"turn, no reasoning-event emission. Drives `tool-rendering`, "
"`tool-rendering-default-catchall`, and "
"`tool-rendering-custom-catchall`."
),
)