MCPcopy Create free account
hub / github.com/microsoft/TypeChat / route_request

Method route_request

python/examples/multiSchema/router.py:31–50  ·  view source on GitHub ↗
(self, line: str)

Source from the content-addressed store, hash-verified

29 self._current_agents[name] = agent
30
31 async def route_request(self, line: str):
32 classes_str = json.dumps(self._current_agents, indent=2, default=lambda o: None, allow_nan=False)
33
34 prompt_fragment = F"""
35Classify ""{line}"" using the following classification table:
36'''
37{classes_str}
38'''
39"""
40
41 result = await self._translator.translate(prompt_fragment)
42 if isinstance(result, Failure):
43 print("Translation Failed ❌")
44 print(f"Context: {result.message}")
45 else:
46 result = result.value
47 print("Translation Succeeded! ✅\n")
48 print(f"The target class is {result['task_kind']}")
49 target = self._current_agents[result["task_kind"]]
50 await target.get("handler")(line)

Callers 1

request_handlerFunction · 0.80

Calls 1

translateMethod · 0.65

Tested by

no test coverage detected