Skip to content

Commit fc9a12b

Browse files
kevinwguanluarss
authored andcommitted
few shot prompting to improve tool call accuracy
Signed-off-by: Kevin Guan <[email protected]>
1 parent b8af583 commit fc9a12b

File tree

2 files changed

+113
-3
lines changed

2 files changed

+113
-3
lines changed

backend/src/agents/retriever_mcp.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from langchain_google_genai import ChatGoogleGenerativeAI
1212
from langchain_ollama import ChatOllama
1313

14+
from ..prompts.tool_examples import mcp_system_prompt, few_shot_examples
1415

1516
class MCP:
1617
llm: ChatVertexAI | ChatGoogleGenerativeAI | ChatOllama
@@ -23,9 +24,19 @@ def mcp_agent(self, state: AgentState) -> dict[str, list[Any]]:
2324
custom_tools = get_tools()
2425
model = self.llm.bind_tools(custom_tools)
2526

26-
run_orfs_chain = (
27-
ChatPromptTemplate.from_template(run_orfs_prompt_template) | model
28-
)
27+
orfs_tmp = ChatPromptTemplate.from_messages([
28+
("system", mcp_system_prompt),
29+
*few_shot_examples,
30+
(
31+
"user",
32+
"Previous conversation:\n{chat_history}\n\nCurrent question:\n{question}",
33+
)
34+
])
35+
36+
#orfs_tmp = ChatPromptTemplate.from_template(run_orfs_prompt_template)
37+
38+
run_orfs_chain = orfs_tmp | model
39+
2940
response = run_orfs_chain.invoke(
3041
{
3142
"question": query,
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
mcp_system_prompt = """
2+
You are an intelligent assistant for managing digital chip design flows using the OpenROAD infrastructure.
3+
4+
Your task:
5+
1. Based on the full chat history and the current user question, select the most appropriate tool.
6+
2. Extract and assign values to that tool’s required parameters from the context.
7+
3. If any parameter cannot be confidently inferred, set its value to `null`.
8+
4. You must pick one of the tools available to you without fail.
9+
"""
10+
11+
few_shot_examples = [
12+
### Start
13+
14+
### get_platforms
15+
{
16+
"role": "user",
17+
"content": "Get list of available platforms and select default plaform."
18+
},
19+
{
20+
"role": "assistant",
21+
"content": """{{
22+
"name": "get_platforms",
23+
"args": {{}}
24+
}}"""
25+
},
26+
###
27+
28+
### get_designs
29+
{
30+
"role": "user",
31+
"content": "Get list of available designs and select default design."
32+
},
33+
{
34+
"role": "assistant",
35+
"content": """{{
36+
"name": "get_designs",
37+
"args": {{}}
38+
}}"""
39+
},
40+
###
41+
42+
### make
43+
{
44+
"role": "user",
45+
"content": "make clean_all"
46+
},
47+
{
48+
"role": "assistant",
49+
"content": """{{
50+
"name": "make",
51+
"args": {{"cmd": "clean_all"}}
52+
}}"""
53+
},
54+
###
55+
56+
### get_stage_names
57+
{
58+
"role": "user",
59+
"content": "Get list of stage names available to run."
60+
},
61+
{
62+
"role": "assistant",
63+
"content": """{{
64+
"name": "get_stage_names",
65+
"args": {{}}
66+
}}"""
67+
},
68+
###
69+
70+
### jump
71+
{
72+
"role": "user",
73+
"content": "jump floorplan"
74+
},
75+
{
76+
"role": "assistant",
77+
"content": """{{
78+
"name": "jump",
79+
"args": {{"stage": "floorplan"}}
80+
}}"""
81+
},
82+
###
83+
84+
### jump
85+
{
86+
"role": "user",
87+
"content": "step"
88+
},
89+
{
90+
"role": "assistant",
91+
"content": """{{
92+
"name": "step",
93+
"args": {{}}
94+
}}"""
95+
},
96+
###
97+
98+
### End
99+
]

0 commit comments

Comments
 (0)