@@ -14,9 +14,7 @@ async def run(self, input: str) -> str:
1414
1515 # Initialize messages list with user input
1616 messages = [{"role" : "user" , "content" : input }]
17- print (f"\n { '=' * 80 } " )
18- print (f"[User] { input } " )
19- print (f"{ '=' * 80 } \n " )
17+ print (f"\n [User] { input } " )
2018
2119 # The agentic loop
2220 while True :
@@ -42,33 +40,25 @@ async def run(self, input: str) -> str:
4240 # First, add the assistant's response to messages
4341 # Convert content blocks to dictionaries for serialization
4442 assistant_content = []
45- print (f"[Agent (Assistant)]" )
4643 for block in result .content :
4744 if block .type == "text" :
48- # assistant's text response
49- print (f" Text: { block .text } " )
5045 assistant_content .append ({"type" : "text" , "text" : block .text })
5146 elif block .type == "tool_use" :
52- print (f" Tool use : { block .name } ( { block . input } ) " )
47+ print (f"[Agent] Calling tool : { block .name } " )
5348 assistant_content .append ({
5449 "type" : "tool_use" ,
5550 "id" : block .id ,
5651 "name" : block .name ,
5752 "input" : block .input
5853 })
59- print ()
6054
6155 messages .append ({"role" : "assistant" , "content" : assistant_content })
6256
6357 # Execute all tool calls and collect results
6458 tool_results = []
65- print (f"[Tool Execution]" )
6659 for block in tool_use_blocks :
67- print (f"[Agent] Tool call: { block .name } ({ block .input } )" )
68-
6960 # Execute the tool
7061 tool_result = await self ._execute_tool (block .name , block .input )
71- print (f" { block .name } -> { tool_result } " )
7262
7363 # Add tool result in Claude's expected format
7464 tool_results .append ({
@@ -80,19 +70,13 @@ async def run(self, input: str) -> str:
8070 # Add tool results as a user message. Claude has only two message roles: user and assistant,
8171 # and the user message role is used to send tool results back to Claude; in this case the content
8272 # block includes the tool result.
83- print (f"\n [User - Tool Results]" )
84- for result in tool_results :
85- print (f" Tool result for { result ['tool_use_id' ]} : { result ['content' ][:100 ]} ..." )
86- print (f"{ '=' * 80 } \n " )
8773 messages .append ({"role" : "user" , "content" : tool_results })
8874 else :
8975 # No tool calls - extract the text response and return
9076 text_blocks = [block for block in result .content if block .type == "text" ]
9177 if text_blocks :
9278 response_text = text_blocks [0 ].text
93- print (f"[Assistant - Final]" )
94- print (f" { response_text } " )
95- print (f"{ '=' * 80 } \n " )
79+ print (f"[Agent] Final response: { response_text } \n " )
9680 return response_text
9781 else :
9882 return "No text response from Claude"
0 commit comments