Files
api_database-api/.trae/documents/Implement Tool Management System for Dynamic Agents.md
2026-01-13 21:23:50 +08:00

44 lines
1.9 KiB
Markdown

# Implement Tool Management for Dynamic Agents
I will implement a system to manage "Tools" (Function Calls) and associate them with Dynamic Agents, allowing the frontend to easily configure which tools an agent can use.
## 1. Database Schema Expansion
I will create two new tables in PostgreSQL:
* `tools`: Stores reusable tool definitions (templates).
* `tool_id`: `SERIAL PRIMARY KEY`
* `name`: `VARCHAR` (Unique, e.g., "get_weather")
* `description`: `TEXT` (For LLM understanding)
* `parameters`: `JSONB` (JSON Schema for arguments)
* `created_at`: `TIMESTAMP`
* `agent_tools`: Maps agents to tools (Many-to-Many).
* `agent_card_id`: `INTEGER` (FK)
* `tool_id`: `INTEGER` (FK)
* `config`: `JSONB` (Optional, for agent-specific tool config if needed)
## 2. API Implementation (`main.py`)
### Pydantic Models
* `ToolCreate`: Validation for creating new tool definitions.
* `ToolResponse`: API response format.
* `AgentToolAssignment`: For linking tools to agents.
### New Endpoints
* **Tool Management (CRUD)**:
* `POST /tools/`: Create a new tool definition.
* `GET /tools/`: List all available tools.
* `PUT /tools/{tool_id}`: Update a tool.
* `DELETE /tools/{tool_id}`: Delete a tool.
* **Agent Tool Association**:
* `POST /agent/{card_id}/tools`: Assign a list of tools to an agent.
* `GET /agent/{card_id}/tools`: Get all tools assigned to an agent.
* `DELETE /agent/{card_id}/tools/{tool_id}`: Remove a tool from an agent.
### Update Existing Logic
* **Modify `GET /dynamic_agent/{card_id}`**:
* Update the query to automatically fetch and include the list of associated tools in the agent details response. This ensures the frontend gets everything in one call.
## 3. Verification
* Create a "Weather Query" tool definition.
* Assign it to a Dynamic Agent.
* Verify the agent details endpoint returns the tool info correctly.