MCPcopy
hub / github.com/langroid/langroid / ask_agent

Method ask_agent

langroid/agent/base.py:2326–2362  ·  view source on GitHub ↗

Send a request to another agent, possibly after confirming with the user. This is not currently used, since we rely on the task loop and `RecipientTool` to address requests to other agents. It is generally best to avoid using this method. Args: a

(
        self,
        agent: "Agent",
        request: str,
        no_answer: str = NO_ANSWER,
        user_confirm: bool = True,
    )

Source from the content-addressed store, hash-verified

2324 ) / 1000
2325
2326 def ask_agent(
2327 self,
2328 agent: "Agent",
2329 request: str,
2330 no_answer: str = NO_ANSWER,
2331 user_confirm: bool = True,
2332 ) -> Optional[str]:
2333 """
2334 Send a request to another agent, possibly after confirming with the user.
2335 This is not currently used, since we rely on the task loop and
2336 `RecipientTool` to address requests to other agents. It is generally best to
2337 avoid using this method.
2338
2339 Args:
2340 agent (Agent): agent to ask
2341 request (str): request to send
2342 no_answer (str): expected response when agent does not know the answer
2343 user_confirm (bool): whether to gate the request with a human confirmation
2344
2345 Returns:
2346 str: response from agent
2347 """
2348 agent_type = type(agent).__name__
2349 if user_confirm:
2350 user_response = Prompt.ask(
2351 f"""[magenta]Here is the request or message:
2352 {request}
2353 Should I forward this to {agent_type}?""",
2354 default="y",
2355 choices=["y", "n"],
2356 )
2357 if user_response not in ["y", "yes"]:
2358 return None
2359 answer = agent.llm_response(request)
2360 if answer != no_answer:
2361 return (f"{agent_type} says: " + str(answer)).strip()
2362 return None

Callers

nothing calls this directly

Calls 1

llm_responseMethod · 0.45

Tested by

no test coverage detected