Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make list_agents paginated #1525

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

feat: make list_agents paginated #1525

wants to merge 11 commits into from

Conversation

cpacker
Copy link
Owner

@cpacker cpacker commented Jul 8, 2024

Closes #1498

Change in API endpoint

GET request is now paginated, in the style of: https://platform.openai.com/docs/api-reference/assistants/listAssistants

Change in data locations

For @goetzrobin: there's some differences in the data coming back from the GET request (apart from it now accepting additional pagination args):

for agent_state, return_dict in zip(agents_states, agents_states_dicts):

"persona" / "human"

            return_dict["persona"] = agent_state._metadata.get("persona", None)
            return_dict["human"] = agent_state._metadata.get("human", None)

This should still be accessible in the List[AgentStateModel] being returned

"tools"

            return_dict["tools"] = [tool for tool in all_available_tools if tool.json_schema in memgpt_agent.functions]

This is now in AgentStateModel.metadata["tools"]

NOTE: this has been moved to a separate GET request: see new route def get_agent_tools (router.get("/agents/{agent_id}/tools)

"memory stats"

            # Add information about memory (raw core, size of recall, size of archival)
            core_memory = memgpt_agent.memory
            recall_memory = memgpt_agent.persistence_manager.recall_memory
            archival_memory = memgpt_agent.persistence_manager.archival_memory
            memory_obj = {
                "core_memory": {section: module.value for (section, module) in core_memory.memory.items()},
                "recall_memory": len(recall_memory) if recall_memory is not None else None,
                "archival_memory": len(archival_memory) if archival_memory is not None else None,
            }
            return_dict["memory"] = memory_obj

This is now in AgentStateModel.metadata["memory_stats"], see new Agent.update_state function

"last run"

            # Add information about last run
            # NOTE: 'last_run' is just the timestamp on the latest message in the buffer
            # Retrieve the Message object via the recall storage or by directly access _messages
            last_msg_obj = memgpt_agent._messages[-1]
            return_dict["last_run"] = last_msg_obj.created_at

This is now in AgentStateModel.metadata["last_run"]

"attached sources"

            # Add information about attached sources
            sources_ids = self.ms.list_attached_sources(agent_id=agent_state.id)
            sources = [self.ms.get_source(source_id=s_id) for s_id in sources_ids]
            return_dict["sources"] = [vars(s) for s in sources]

This is now in AgentStateModel.metadata["sources"]

NOTE: this has been moved to a separate GET request: def get_agent_sources (/agents/{agent_id}/sources)

^extra note @goetzrobin these metadata fields may be null for old agents, since they are stored inside of metadata they will get refreshed on .step(), so only agents that have been run post-PR will have the metadata fields. The frontend should have sane defaults / not crash on null accordingly.

memgpt/server/server.py Outdated Show resolved Hide resolved
memgpt/server/server.py Outdated Show resolved Hide resolved
# - last run data
# - memory stats (recall, archival)
# - number of sources
return [agentstate_to_agentstatemodel(a_s) for a_s in agents_states]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to do the conversion in the REST API, since if you just return List[AgentState] then the LocalClient can directly use this

memgpt/server/rest_api/agents/index.py Outdated Show resolved Hide resolved
memgpt/server/rest_api/agents/index.py Outdated Show resolved Hide resolved
memgpt/agent.py Show resolved Hide resolved
memgpt/server/server.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To triage
Development

Successfully merging this pull request may close these issues.

[API] Make GET agents paginated
2 participants