mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-22 11:41:02 +02:00
Agent call to mcp-tool is working with a hard-coded service.
- Added ToolClientSpec and ToolClient to implement a tool call. - Updated agent-manager-react to invoke an MCP tool with a tool defined with 'mcp-tool' type. Not generic, need to work out how to call the right parameters.
This commit is contained in:
parent
e56186054a
commit
3978d35545
5 changed files with 85 additions and 5 deletions
|
|
@ -29,4 +29,5 @@ from . document_embeddings_client import DocumentEmbeddingsClientSpec
|
|||
from . agent_service import AgentService
|
||||
from . graph_rag_client import GraphRagClientSpec
|
||||
from . tool_service import ToolService
|
||||
from . tool_client import ToolClientSpec
|
||||
|
||||
|
|
|
|||
40
trustgraph-base/trustgraph/base/tool_client.py
Normal file
40
trustgraph-base/trustgraph/base/tool_client.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
import json
|
||||
|
||||
from . request_response_spec import RequestResponse, RequestResponseSpec
|
||||
from .. schema import ToolRequest, ToolResponse
|
||||
|
||||
class ToolClient(RequestResponse):
|
||||
|
||||
async def invoke(self, name, parameters={}, timeout=600):
|
||||
|
||||
if parameters is None:
|
||||
parameters = {}
|
||||
|
||||
resp = await self.request(
|
||||
ToolRequest(
|
||||
name = name,
|
||||
parameters = json.dumps(parameters),
|
||||
),
|
||||
timeout=timeout
|
||||
)
|
||||
|
||||
if resp.error:
|
||||
raise RuntimeError(resp.error.message)
|
||||
|
||||
if resp.text: return resp.text
|
||||
|
||||
return json.loads(resp.object)
|
||||
|
||||
class ToolClientSpec(RequestResponseSpec):
|
||||
def __init__(
|
||||
self, request_name, response_name,
|
||||
):
|
||||
super(ToolClientSpec, self).__init__(
|
||||
request_name = request_name,
|
||||
request_schema = ToolRequest,
|
||||
response_name = response_name,
|
||||
response_schema = ToolResponse,
|
||||
impl = ToolClient,
|
||||
)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue