MCPcopy
hub / github.com/CopilotKit/CopilotKit / execute_agent

Method execute_agent

sdk-python/copilotkit/sdk.py:297–344  ·  view source on GitHub ↗

Execute an agent

(  # pylint: disable=too-many-arguments
        self,
        *,
        context: CopilotKitContext,
        name: str,
        thread_id: str,
        state: dict,
        config: Optional[dict] = None,
        messages: List[Message],
        actions: List[ActionDict],
        node_name: str,
        meta_events: Optional[List[MetaEvent]] = None,
    )

Source from the content-addressed store, hash-verified

295 raise ActionExecutionException(name, error) from error
296
297 def execute_agent( # pylint: disable=too-many-arguments
298 self,
299 *,
300 context: CopilotKitContext,
301 name: str,
302 thread_id: str,
303 state: dict,
304 config: Optional[dict] = None,
305 messages: List[Message],
306 actions: List[ActionDict],
307 node_name: str,
308 meta_events: Optional[List[MetaEvent]] = None,
309 ) -> Any:
310 """
311 Execute an agent
312 """
313 agents = self.agents(context) if callable(self.agents) else self.agents
314 agent = next((agent for agent in agents if agent.name == name), None)
315 if agent is None:
316 raise AgentNotFoundException(name)
317
318 self._log_request_info(
319 title="Handling execute agent request:",
320 data=[
321 ("Context", context),
322 ("Agent", agent.dict_repr()),
323 ("Thread ID", thread_id),
324 ("Node Name", node_name),
325 ("State", state),
326 ("Config", config),
327 ("Messages", messages),
328 ("Actions", actions),
329 ("MetaEvents", meta_events),
330 ],
331 )
332
333 try:
334 return agent.execute(
335 thread_id=thread_id,
336 node_name=node_name,
337 state=state,
338 config=config,
339 messages=messages,
340 actions=actions,
341 meta_events=meta_events,
342 )
343 except Exception as error:
344 raise AgentExecutionException(name, error) from error
345
346 async def get_agent_state(
347 self,

Callers 1

handle_execute_agentFunction · 0.80

Calls 7

_log_request_infoMethod · 0.95
executeMethod · 0.65
nextFunction · 0.50
agentsMethod · 0.45
dict_reprMethod · 0.45

Tested by

no test coverage detected