Fix/agent groups broken (#504)

* Fix non-backward-compatible agent changes

* Fix broken agents
This commit is contained in:
cybermaggedon 2025-09-08 21:17:18 +01:00 committed by GitHub
parent f22bf13aa6
commit 5867f45c3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 11 deletions

View file

@ -132,17 +132,25 @@ class FlowInstance:
input input
)["response"] )["response"]
def agent(self, question, user="trustgraph", state="", group=None, history=None): def agent(self, question, user="trustgraph", state=None, group=None, history=None):
# The input consists of a question and optional context # The input consists of a question and optional context
input = { input = {
"question": question, "question": question,
"user": user, "user": user,
"state": state,
"group": group or [],
"history": history or []
} }
# Only include state if it has a value
if state is not None:
input["state"] = state
# Only include group if it has a value
if group is not None:
input["group"] = group
# Always include history (empty list if None)
input["history"] = history or []
return self.request( return self.request(
"service/agent", "service/agent",
input input

View file

@ -9,8 +9,8 @@ class AgentRequestTranslator(MessageTranslator):
def to_pulsar(self, data: Dict[str, Any]) -> AgentRequest: def to_pulsar(self, data: Dict[str, Any]) -> AgentRequest:
return AgentRequest( return AgentRequest(
question=data["question"], question=data["question"],
state=data.get("state", ""), state=data.get("state", None),
group=data.get("group", []), group=data.get("group", None),
history=data.get("history", []), history=data.get("history", []),
user=data.get("user", "trustgraph") user=data.get("user", "trustgraph")
) )

View file

@ -29,7 +29,7 @@ def output(text, prefix="> ", width=78):
async def question( async def question(
url, question, flow_id, user, collection, url, question, flow_id, user, collection,
plan=None, state=None, verbose=False plan=None, state=None, group=None, verbose=False
): ):
if not url.endswith("/"): if not url.endswith("/"):
@ -55,19 +55,24 @@ async def question(
async with connect(url) as ws: async with connect(url) as ws:
req = json.dumps({ req = {
"id": mid, "id": mid,
"service": "agent", "service": "agent",
"flow": flow_id, "flow": flow_id,
"request": { "request": {
"question": question, "question": question,
"user": user, "user": user,
"state": state or "",
"group": [],
"history": [] "history": []
} }
}
}) # Only add optional fields if they have values
if state is not None:
req["request"]["state"] = state
if group is not None:
req["request"]["group"] = group
req = json.dumps(req)
await ws.send(req) await ws.send(req)
@ -144,6 +149,12 @@ def main():
help=f'Agent initial state (default: unspecified)' help=f'Agent initial state (default: unspecified)'
) )
parser.add_argument(
'-g', '--group',
nargs='+',
help='Agent tool groups (can specify multiple)'
)
parser.add_argument( parser.add_argument(
'-v', '--verbose', '-v', '--verbose',
action="store_true", action="store_true",
@ -163,6 +174,7 @@ def main():
collection = args.collection, collection = args.collection,
plan = args.plan, plan = args.plan,
state = args.state, state = args.state,
group = args.group,
verbose = args.verbose, verbose = args.verbose,
) )
) )