3434from camel .types .agents import ToolCallingRecord
3535from pydantic import BaseModel
3636
37- from app .utils .event_loop_utils import _schedule_async_task
3837from app .service .task import (
3938 Action ,
4039 ActionActivateAgentData ,
4544 get_task_lock ,
4645 set_process_task ,
4746)
47+ from app .utils .event_loop_utils import _schedule_async_task
4848
4949# Logger for agent tracking
5050logger = logging .getLogger ("agent" )
@@ -162,7 +162,7 @@ def _extract_tokens(response) -> int:
162162 return usage_info .get ("total_tokens" , 0 )
163163
164164 def _stream_chunks (self , response_gen ):
165- """Generator that wraps a streaming response and sends chunks to frontend.
165+ """Generator wrapping streaming response for frontend.
166166
167167 Args:
168168 response_gen: The original streaming response generator
@@ -171,7 +171,7 @@ def _stream_chunks(self, response_gen):
171171 Each chunk from the original generator
172172
173173 Returns:
174- Tuple of (accumulated_content, total_tokens) via StopIteration value
174+ Tuple of (accumulated_content, total_tokens) via StopIteration
175175 """
176176 accumulated_content = ""
177177 last_chunk = None
@@ -187,7 +187,7 @@ def _stream_chunks(self, response_gen):
187187 self ._send_agent_deactivate (accumulated_content , total_tokens )
188188
189189 async def _astream_chunks (self , response_gen ):
190- """Async generator that wraps a streaming response and sends chunks to frontend.
190+ """Async generator wrapping streaming response for frontend.
191191
192192 Args:
193193 response_gen: The original async streaming response generator
@@ -546,7 +546,7 @@ async def _aexecute_tool(
546546 if hasattr (tool , "_toolkit_name" ):
547547 toolkit_name = tool ._toolkit_name
548548
549- # Method 2: For MCP tools, check if func has __self__ (the toolkit instance)
549+ # Method 2: For MCP tools, check if func has __self__
550550 if (
551551 not toolkit_name
552552 and hasattr (tool , "func" )
@@ -602,7 +602,7 @@ async def _aexecute_tool(
602602 # Try different invocation paths in order of preference
603603 if hasattr (tool , "func" ) and hasattr (tool .func , "async_call" ):
604604 # Case: FunctionTool wrapping an MCP tool
605- # Check if the wrapped tool is sync to avoid run_in_executor
605+ # Check if wrapped tool is sync to avoid executor
606606 if hasattr (tool , "is_async" ) and not tool .is_async :
607607 # Sync tool: call directly to preserve ContextVar
608608 result = tool (** args )
@@ -620,7 +620,7 @@ async def _aexecute_tool(
620620 # Sync tool: call directly to preserve ContextVar
621621 # in same thread
622622 result = tool (** args )
623- # Handle case where synchronous call returns a coroutine
623+ # Handle sync call returning a coroutine
624624 if asyncio .iscoroutine (result ):
625625 result = await result
626626 else :
@@ -638,7 +638,7 @@ async def _aexecute_tool(
638638 result = await tool (** args )
639639
640640 else :
641- # Fallback: synchronous call - call directly in current context
641+ # Fallback: sync call directly in current context
642642 # DO NOT use run_in_executor to preserve ContextVar
643643 result = tool (** args )
644644 # Handle case where synchronous call returns a coroutine
@@ -713,7 +713,9 @@ def clone(self, with_memory: bool = False) -> ChatAgent:
713713 schema for schema in self ._external_tool_schemas .values ()
714714 ],
715715 response_terminators = self .response_terminators ,
716- scheduling_strategy = self .model_backend .scheduling_strategy .__name__ ,
716+ scheduling_strategy = (
717+ self .model_backend .scheduling_strategy .__name__
718+ ),
717719 max_iteration = self .max_iteration ,
718720 stop_event = self .stop_event ,
719721 tool_execution_timeout = self .tool_execution_timeout ,
0 commit comments