mirror of
https://github.com/cpacker/MemGPT.git
synced 2025-06-03 04:30:22 +00:00
feat: add ability to list agents by name
for REST API and python SDK (#1982)
This commit is contained in:
parent
46753b7357
commit
9cf16b2cfd
@ -16,7 +16,7 @@
|
||||
</h3>
|
||||
|
||||
**👾 Letta** is an open source framework for building stateful LLM applications. You can use Letta to build **stateful agents** with advanced reasoning capabilities and transparent long-term memory. The Letta framework is white box and model-agnostic.
|
||||
|
||||
|
||||
[](https://discord.gg/letta)
|
||||
[](https://twitter.com/Letta_AI)
|
||||
[](https://arxiv.org/abs/2310.08560)
|
||||
|
@ -612,7 +612,12 @@ class RESTClient(AbstractClient):
|
||||
agent_id (str): ID of the agent
|
||||
"""
|
||||
# TODO: implement this
|
||||
raise NotImplementedError
|
||||
response = requests.get(f"{self.base_url}/{self.api_prefix}/agents", headers=self.headers, params={"name": agent_name})
|
||||
agents = [AgentState(**agent) for agent in response.json()]
|
||||
if len(agents) == 0:
|
||||
return None
|
||||
assert len(agents) == 1, f"Multiple agents with the same name: {agents}"
|
||||
return agents[0].id
|
||||
|
||||
# memory
|
||||
def get_in_context_memory(self, agent_id: str) -> Memory:
|
||||
|
@ -40,6 +40,7 @@ router = APIRouter(prefix="/agents", tags=["agents"])
|
||||
|
||||
@router.get("/", response_model=List[AgentState], operation_id="list_agents")
|
||||
def list_agents(
|
||||
name: Optional[str] = Query(None, description="Name of the agent"),
|
||||
server: "SyncServer" = Depends(get_letta_server),
|
||||
user_id: Optional[str] = Header(None, alias="user_id"), # Extract user_id from header, default to None if not present
|
||||
):
|
||||
@ -49,7 +50,11 @@ def list_agents(
|
||||
"""
|
||||
actor = server.get_user_or_default(user_id=user_id)
|
||||
|
||||
return server.list_agents(user_id=actor.id)
|
||||
agents = server.list_agents(user_id=actor.id)
|
||||
# TODO: move this logic to the ORM
|
||||
if name:
|
||||
agents = [a for a in agents if a.name == name]
|
||||
return agents
|
||||
|
||||
|
||||
@router.get("/{agent_id}/context", response_model=ContextWindowOverview, operation_id="get_agent_context_window")
|
||||
|
@ -103,6 +103,10 @@ def test_agent(client: Union[LocalClient, RESTClient], agent: AgentState):
|
||||
renamed_agent = client.get_agent(agent_id=agent.id)
|
||||
assert renamed_agent.name == new_name, "Agent renaming failed"
|
||||
|
||||
# get agent id
|
||||
agent_id = client.get_agent_id(agent_name=new_name)
|
||||
assert agent_id == agent.id, "Agent ID retrieval failed"
|
||||
|
||||
# test client.delete_agent and client.agent_exists
|
||||
delete_agent = client.create_agent(name="DeleteTestAgent")
|
||||
assert client.agent_exists(agent_id=delete_agent.id), "Agent creation failed"
|
||||
|
Loading…
Reference in New Issue
Block a user