forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhitl_in_chat_agent.py
More file actions
58 lines (46 loc) · 2.14 KB
/
Copy pathhitl_in_chat_agent.py
File metadata and controls
58 lines (46 loc) · 2.14 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
"""MS Agent Framework agent backing the In-Chat HITL (useHumanInTheLoop) demo.
The `book_call` tool is defined entirely on the frontend via
`useHumanInTheLoop`. CopilotKit's runtime forwards the frontend tool
definition to the agent at request time, so this agent has no backend tools
of its own -- it just needs to recognize "book a call" intent and emit the
tool call.
When the user picks a slot (or cancels), CopilotKit returns that choice as
the tool result and the agent confirms in a short follow-up message.
"""
from __future__ import annotations
from textwrap import dedent
from agent_framework import Agent, BaseChatClient
from agent_framework_ag_ui import AgentFrameworkAgent
SYSTEM_PROMPT = dedent(
"""
You help users book an onboarding or intro call with the sales team.
When the user asks to book a call, schedule a meeting, or set up a 1:1,
call the frontend-provided `book_call` tool with:
- `topic`: a short summary of what the call is about (e.g. 'Intro with
sales', 'Q2 goals review').
- `attendee`: who the call is with, if known (e.g. 'Alice from Sales').
The tool surfaces a time-picker UI inside the chat. The user will pick a
slot or cancel. After the tool returns, send one short confirmation
sentence reflecting the user's choice (or noting cancellation). Do NOT
ask for approval yourself -- always call the tool and let the picker
handle the decision. Keep all replies to one sentence.
"""
).strip()
def create_hitl_in_chat_agent(chat_client: BaseChatClient) -> AgentFrameworkAgent:
"""Instantiate the In-Chat HITL demo agent."""
base_agent = Agent(
client=chat_client,
name="hitl_in_chat_agent",
instructions=SYSTEM_PROMPT,
# `book_call` is registered on the frontend via `useHumanInTheLoop`.
tools=[],
)
return AgentFrameworkAgent(
agent=base_agent,
name="CopilotKitMSAgentHitlInChatAgent",
description=(
"Scheduling assistant that delegates the time-picker interaction "
"to a frontend-defined `book_call` tool rendered inline in the chat."
),
require_confirmation=False,
)