MCPcopy
hub / github.com/langroid/langroid / test_task_2_agent_2_tool

Function test_task_2_agent_2_tool

tests/main/test_task.py:546–707  ·  view source on GitHub ↗

QueryTool: Task A uses and handles (validates), Task B handles but doesn't use FeedbackTool: Task B uses and handles (validates), Task A handles but doesn't use

(
    test_settings: Settings,
    use_fn_api: bool,
    use_tools_api: bool,
    use_orch_tools: bool,
)

Source from the content-addressed store, hash-verified

544@pytest.mark.parametrize("use_tools_api", [True, False])
545@pytest.mark.parametrize("use_orch_tools", [True, False])
546def test_task_2_agent_2_tool(
547 test_settings: Settings,
548 use_fn_api: bool,
549 use_tools_api: bool,
550 use_orch_tools: bool,
551):
552 """
553 QueryTool: Task A uses and handles (validates), Task B handles but doesn't use
554 FeedbackTool: Task B uses and handles (validates), Task A handles but doesn't use
555 """
556
557 set_global(test_settings)
558
559 class QueryTool(ToolMessage):
560 request: str = "polinsky_query"
561 purpose: str = """
562 Ask whether the Polinsky transform of a <number> equals <value>.
563 """
564 number: int
565 value: int
566
567 class FeedbackTool(ToolMessage):
568 request: str = "polinsky_feedback"
569 purpose: str = """
570 Given a <number>, respond with the Polinsky transform of the number.
571 """
572 feedback: str
573
574 class Requestor(ChatAgent):
575 def __init__(self, config: ChatAgentConfig):
576 super().__init__(config)
577 self.enable_message(QueryTool, use=True, handle=True)
578 self.enable_message(FeedbackTool, use=False, handle=True)
579 self.enable_message(DoneTool)
580
581 def polinsky_query(self, msg: QueryTool) -> str | PassTool:
582 # No validation err, so pass it on so other agent can respond
583 return PassTool() if use_orch_tools else PASS
584
585 def polinsky_feedback(self, msg: FeedbackTool) -> str:
586 """Transmit feedback received from other agent, to this agent's LLM"""
587 if msg.feedback.strip() == "":
588 return f"""
589 CORRECT, the value you gave IS the Polinsky transform of that number.
590 Please proceed with requesting the Polinsky transform of
591 the NEXT number on your list, or if you&#x27;re finished, use the
592 TOOL `{DoneTool.name()}` with `content` set to the summary of the
593 transformations, in this format:
594 '(number1, transform1), (number2, transform2)'
595 """
596 else:
597 return f"""
598 WRONG, please try again based on this feedback:
599 {msg.feedback}
600 """
601
602 def handle_message_fallback(self, msg: str | ChatDocument) -> Any:
603 if isinstance(msg, ChatDocument) and msg.metadata.sender == Entity.LLM:

Callers

nothing calls this directly

Calls 10

add_sub_taskMethod · 0.95
runMethod · 0.95
set_globalFunction · 0.90
ChatAgentConfigClass · 0.90
TaskClass · 0.90
RequestorClass · 0.85
CriticClass · 0.85
default_valueMethod · 0.80
nameMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…