trustgraph/trustgraph-base/trustgraph/base/agent_client.py
cybermaggedon d83e4e3d59
Update to enable knowledge extraction using the agent framework (#439)
* Implement KG extraction agent (kg-extract-agent)

* Using ReAct framework (agent-manager-react)
 
* ReAct manager had an issue when emitting JSON, which conflicts which ReAct manager's own JSON messages, so refactored ReAct manager to use traditional ReAct messages, non-JSON structure.
 
* Minor refactor to take the prompt template client out of prompt-template so it can be more readily used by other modules. kg-extract-agent uses this framework.
2025-07-21 14:31:57 +01:00

37 lines
1.1 KiB
Python

from . request_response_spec import RequestResponse, RequestResponseSpec
from .. schema import AgentRequest, AgentResponse
from .. knowledge import Uri, Literal
class AgentClient(RequestResponse):
async def invoke(self, recipient, question, plan=None, state=None,
history=[], timeout=300):
resp = await self.request(
AgentRequest(
question = question,
plan = plan,
state = state,
history = history,
),
recipient=recipient,
timeout=timeout,
)
if resp.error:
raise RuntimeError(resp.error.message)
return resp.answer
class AgentClientSpec(RequestResponseSpec):
def __init__(
self, request_name, response_name,
):
super(AgentClientSpec, self).__init__(
request_name = request_name,
request_schema = AgentRequest,
response_name = response_name,
response_schema = AgentResponse,
impl = AgentClient,
)