Skip to content

Commit

Permalink
feat(router): hide agent parameters for public API
Browse files Browse the repository at this point in the history
  • Loading branch information
polebug committed Jan 24, 2025
1 parent bd0d1ed commit a8a50df
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion openagent/router/routes/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from openagent.router.routes.models.response import (
AgentListResponse,
AgentResponse,
PublicAgentResponse,
ResponseModel,
)
from openagent.tools import BaseTool, ToolConfig, get_tool_executor
Expand Down Expand Up @@ -143,7 +144,7 @@ def list_agents(
return ResponseModel(
code=status.HTTP_200_OK,
data=AgentListResponse(
agents=[AgentResponse.model_validate(agent) for agent in agents],
agents=[PublicAgentResponse.model_validate(agent) for agent in agents],
total=total,
),
message=f"Retrieved {len(agents)} agents out of {total}",
Expand Down
45 changes: 44 additions & 1 deletion openagent/router/routes/models/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,54 @@ class AgentResponse(BaseModel):
created_at: datetime
updated_at: datetime

class PublicToolConfigResponse(BaseModel):
model_config = ConfigDict(from_attributes=True)

name: str
description: str | None = None
tool_id: int
model_id: int

class PublicAgentResponse(BaseModel):
model_config = ConfigDict(from_attributes=True)

id: int
name: str
description: str | None = None
personality: str | None = None
instruction: str | None = None
wallet_address: str
token_image: str | None = None
ticker: str
contract_address: str | None = None
pair_address: str | None = None
twitter: str | None = None
telegram: str | None = None
website: str | None = None
tool_configs: list[PublicToolConfigResponse] | None = None
type: AgentType
status: AgentStatus
created_at: datetime
updated_at: datetime

@classmethod
def from_orm(cls, obj):
if hasattr(obj, 'tool_configs') and obj.tool_configs:
obj.tool_configs = [
PublicToolConfigResponse(
name=tc['name'],
description=tc.get('description'),
tool_id=tc['tool_id'],
model_id=tc['model_id']
)
for tc in obj.tool_configs
]
return super().from_orm(obj)

class AgentListResponse(BaseModel):
model_config = ConfigDict(from_attributes=True)

agents: list[AgentResponse]
agents: list[PublicAgentResponse]
total: int


Expand Down

0 comments on commit a8a50df

Please sign in to comment.