Previously, the list endpoint always returned soul=null because
_agent_config_to_response() was called without include_soul=True.
This caused confusion since PUT /api/agents/{name} and GET /api/agents/{name}
both returned the soul content, but the list endpoint silently omitted it.
Co-authored-by: octo-patch <octo-patch@users.noreply.github.com>
This commit is contained in:
parent
5f8dac66e6
commit
a283d4a02d
|
|
@ -24,7 +24,7 @@ class AgentResponse(BaseModel):
|
||||||
description: str = Field(default="", description="Agent description")
|
description: str = Field(default="", description="Agent description")
|
||||||
model: str | None = Field(default=None, description="Optional model override")
|
model: str | None = Field(default=None, description="Optional model override")
|
||||||
tool_groups: list[str] | None = Field(default=None, description="Optional tool group whitelist")
|
tool_groups: list[str] | None = Field(default=None, description="Optional tool group whitelist")
|
||||||
soul: str | None = Field(default=None, description="SOUL.md content (included on GET /{name})")
|
soul: str | None = Field(default=None, description="SOUL.md content")
|
||||||
|
|
||||||
|
|
||||||
class AgentsListResponse(BaseModel):
|
class AgentsListResponse(BaseModel):
|
||||||
|
|
@ -92,17 +92,17 @@ def _agent_config_to_response(agent_cfg: AgentConfig, include_soul: bool = False
|
||||||
"/agents",
|
"/agents",
|
||||||
response_model=AgentsListResponse,
|
response_model=AgentsListResponse,
|
||||||
summary="List Custom Agents",
|
summary="List Custom Agents",
|
||||||
description="List all custom agents available in the agents directory.",
|
description="List all custom agents available in the agents directory, including their soul content.",
|
||||||
)
|
)
|
||||||
async def list_agents() -> AgentsListResponse:
|
async def list_agents() -> AgentsListResponse:
|
||||||
"""List all custom agents.
|
"""List all custom agents.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List of all custom agents with their metadata (without soul content).
|
List of all custom agents with their metadata and soul content.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
agents = list_custom_agents()
|
agents = list_custom_agents()
|
||||||
return AgentsListResponse(agents=[_agent_config_to_response(a) for a in agents])
|
return AgentsListResponse(agents=[_agent_config_to_response(a, include_soul=True) for a in agents])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to list agents: {e}", exc_info=True)
|
logger.error(f"Failed to list agents: {e}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=f"Failed to list agents: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"Failed to list agents: {str(e)}")
|
||||||
|
|
|
||||||
|
|
@ -439,6 +439,15 @@ class TestAgentsAPI:
|
||||||
assert "agent-one" in names
|
assert "agent-one" in names
|
||||||
assert "agent-two" in names
|
assert "agent-two" in names
|
||||||
|
|
||||||
|
def test_list_agents_includes_soul(self, agent_client):
|
||||||
|
agent_client.post("/api/agents", json={"name": "soul-agent", "soul": "My soul content"})
|
||||||
|
|
||||||
|
response = agent_client.get("/api/agents")
|
||||||
|
assert response.status_code == 200
|
||||||
|
agents = response.json()["agents"]
|
||||||
|
soul_agent = next(a for a in agents if a["name"] == "soul-agent")
|
||||||
|
assert soul_agent["soul"] == "My soul content"
|
||||||
|
|
||||||
def test_get_agent(self, agent_client):
|
def test_get_agent(self, agent_client):
|
||||||
agent_client.post("/api/agents", json={"name": "test-agent", "soul": "Hello world"})
|
agent_client.post("/api/agents", json={"name": "test-agent", "soul": "Hello world"})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue