diff --git a/agents-api/agents_api/queries/chat/prepare_chat_context.py b/agents-api/agents_api/queries/chat/prepare_chat_context.py index 4731618f8..d878e1bd4 100644 --- a/agents-api/agents_api/queries/chat/prepare_chat_context.py +++ b/agents-api/agents_api/queries/chat/prepare_chat_context.py @@ -2,24 +2,35 @@ from uuid import UUID from beartype import beartype -from fastapi import HTTPException -from pydantic import ValidationError from ...common.protocol.sessions import ChatContext, make_session from ..session.prepare_session_data import prepare_session_data from ..utils import ( - cozo_query, - fix_uuid_if_present, - partialclass, - rewrap_exceptions, - verify_developer_id_query, - verify_developer_owns_resource_query, wrap_in_class, ) ModelT = TypeVar("ModelT", bound=Any) T = TypeVar("T") +#tool_id, name, type, spec, description, updated_at, created_at +get_agent_query = """ +SELECT + session_lookup.agent_id, + tools.tool_id, + tools.name, + tools.type, + tools.spec, + tools.description, + tools.updated_at, + tools.created_at +FROM session_lookup +JOIN ON tools +WHERE + developer_id = $1 AND + session_id = $2 and participant_type == 'agent AND + session_lookup.agent_id = tools.agent_id +""" + # TODO: implement this part # @rewrap_exceptions( @@ -68,75 +79,12 @@ def prepare_chat_context( developer_id=developer_id, session_id=session_id ) - session_data_fields = ("session", "agents", "users") - - session_data_query += """ - :create _session_data_json { - agents: [Json], - users: [Json], - session: Json, - } - """ - - toolsets_query = """ - input[session_id] <- [[to_uuid($session_id)]] - - tools_by_agent[agent_id, collect(tool)] := - input[session_id], - *session_lookup{ - session_id, - participant_id: agent_id, - participant_type: "agent", - }, - - *tools { agent_id, tool_id, name, type, spec, description, updated_at, created_at }, - tool = { - "id": tool_id, - "name": name, - "type": type, - "spec": spec, - "description": description, - "updated_at": updated_at, - "created_at": created_at, - } - - agent_toolsets[collect(toolset)] := - tools_by_agent[agent_id, tools], - toolset = { - "agent_id": agent_id, - "tools": tools, - } - - ?[toolsets] := - agent_toolsets[toolsets] - - :create _toolsets_json { - toolsets: [Json], - } - """ - - combine_query = f""" - ?[{', '.join(session_data_fields)}, toolsets] := - *_session_data_json {{ {', '.join(session_data_fields)} }}, - *_toolsets_json {{ toolsets }} - - :limit 1 - """ - queries = [ - verify_developer_id_query(developer_id), - verify_developer_owns_resource_query( - developer_id, "sessions", session_id=session_id - ), session_data_query, - toolsets_query, - combine_query, + get_agent_query ] return ( queries, - { - "session_id": str(session_id), - **sd_vars, - }, + [developer_id, session_id], )