@@ -15,11 +15,12 @@ def __init__(self, config=None, **kwargs):
1515 Initialize the dummy client.
1616 AutoGen passes config as first positional argument, then kwargs.
1717 """
18- # Merge config dict if provided
1918 if isinstance (config , dict ):
2019 kwargs .update (config )
2120 self .model = kwargs .get ("model" , "dummy-model" )
21+ self .calls_per_tool = kwargs .get ("calls_per_tool" , 1 )
2222 self .fixed_tool_names = []
23+ self ._tool_call_count = 0
2324
2425 def create (self , params : Dict [str , Any ]) -> Any :
2526 """
@@ -29,42 +30,36 @@ def create(self, params: Dict[str, Any]) -> Any:
2930 messages = params .get ("messages" , [])
3031 tools = params .get ("tools" , [])
3132
32- # Extract tool names if available
3333 if tools :
3434 self .fixed_tool_names = [
3535 tool .get ("function" , {}).get ("name" , tool .get ("name" , "" ))
3636 for tool in tools
3737 if tool .get ("function" , {}).get ("name" ) or tool .get ("name" )
3838 ]
3939
40- # Check if last message is a tool result
4140 last_message = messages [- 1 ] if messages else {}
42- if last_message .get ("role" ) == "tool" or any (
41+ is_tool_result = last_message .get ("role" ) == "tool" or any (
4342 msg .get ("role" ) == "tool" for msg in messages [- 3 :]
44- ):
45- # Return a simple completion after tool execution
46- return DummyResponse (
47- content = "I have finished the HPC tasks. TERMINATE" , model = self .model
48- )
43+ )
4944
50- # If tools are available, return tool calls
51- if self .fixed_tool_names :
52- tool_calls = []
53- for name in self .fixed_tool_names :
54- tool_calls .append (
55- {
56- "id" : f"call_{ uuid .uuid4 ().hex [:8 ]} " ,
57- "type" : "function" ,
58- "function" : {
59- "name" : name ,
60- "arguments" : "{}" , # Empty args as requested
61- },
62- }
45+ if is_tool_result :
46+ self ._tool_call_count += 1
47+ if self ._tool_call_count >= self .calls_per_tool :
48+ return DummyResponse (
49+ content = "I have finished the HPC tasks. TERMINATE" , model = self .model
6350 )
6451
52+ if self .fixed_tool_names :
53+ tool_calls = [
54+ {
55+ "id" : f"call_{ uuid .uuid4 ().hex [:8 ]} " ,
56+ "type" : "function" ,
57+ "function" : {"name" : name , "arguments" : "{}" },
58+ }
59+ for name in self .fixed_tool_names
60+ ]
6561 return DummyResponse (content = "" , tool_calls = tool_calls , model = self .model )
6662
67- # Default: return a simple message
6863 return DummyResponse (content = "I understand. TERMINATE" , model = self .model )
6964
7065 def message_retrieval (self , response : Any ) -> List [Dict [str , Any ]]:
0 commit comments