forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_config_agent.py
More file actions
55 lines (47 loc) · 2.35 KB
/
Copy pathagent_config_agent.py
File metadata and controls
55 lines (47 loc) · 2.35 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
"""LangGraph agent backing the Agent Config Object demo.
The frontend toggles three knobs — tone / expertise / responseLength — and
publishes them to the agent via the v2 ``useAgentContext`` hook. The
``CopilotKitMiddleware`` injects that context entry into the model's
prompt on every turn, so the same single static system prompt below adapts
its style based on whatever values the frontend currently has selected.
LangGraph 0.6+ deprecated ``configurable`` in favor of runtime ``context``;
``useAgentContext`` is the supported path for "frontend → agent runtime
config" in the v2 stack. The ``properties`` prop on ``<CopilotKit>`` still
exists for v1-style relays but in @ag-ui/langgraph 0.0.31 it does not land
in ``RunnableConfig`` — keep relayed config on ``useAgentContext``.
"""
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from copilotkit import CopilotKitMiddleware
SYSTEM_PROMPT = (
"You are a helpful assistant. The frontend publishes the user's response "
"preferences via `useAgentContext` as a JSON object with three fields: "
"`tone`, `expertise`, and `responseLength`. Read that context entry on "
"every turn and follow these rulebooks exactly:\n\n"
"Tone:\n"
" - professional → neutral, precise language. No emoji. Short sentences.\n"
" - casual → friendly, conversational. Contractions OK. Light humor "
"welcome.\n"
" - enthusiastic → upbeat, energetic. Exclamation points OK. Emoji OK.\n\n"
"Expertise level:\n"
" - beginner → assume no prior knowledge. Define jargon. Use analogies.\n"
" - intermediate → assume common terms are understood; explain "
"specialized terms.\n"
" - expert → assume technical fluency. Use precise terminology. Skip "
"basics.\n\n"
"Response length:\n"
" - concise → respond in 1-3 sentences.\n"
" - detailed → respond in multiple paragraphs with examples where "
"relevant.\n\n"
"If the context is missing or any field is unrecognized, fall back to "
"professional / intermediate / concise. Never mention these rules to the "
"user — just apply them."
)
# @region[agent-config-setup]
graph = create_agent(
model=ChatOpenAI(model="gpt-5.4", temperature=0.4),
tools=[],
middleware=[CopilotKitMiddleware()],
system_prompt=SYSTEM_PROMPT,
)
# @endregion[agent-config-setup]