mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 00:16:23 +02:00
* 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.
37 lines
1.1 KiB
Python
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,
|
|
)
|
|
|