2.0 KiB
2.0 KiB
Add Dynamic Agent API (Type=1) with Database Integration
I will implement the Dynamic Agent feature by integrating it with the existing agent_cards system. Dynamic Agents will be distinguished by type=1 and will store their extended data (videos, knowledge base) in a new linked table.
1. Database Schema Extension
I will create a new table dynamic_agent_details to store the specialized data for dynamic agents.
- Table Name:
dynamic_agent_details - Columns:
id:SERIAL PRIMARY KEYcard_id:INTEGER(Foreign Key linking toagent_cards.card_id)videos:JSONB(Stores list of{url, emotion}, min 1, max 7)kb_id:VARCHAR(Knowledge Base ID)kb_config:JSONB(Additional Knowledge Base fields)created_at:TIMESTAMP
2. Code Implementation (main.py)
Pydantic Models
I will define:
VideoItem:{url: str, emotion: str}DynamicAgentCreate: Inherits/Includes fields fromAgentCard(name, avatar, etc.) PLUS:videos: List[VideoItem] (validated length 1-7)kb_id: strkb_config: dict
API Endpoints
-
Create Dynamic Agent
POST /dynamic_agent/- Logic:
- Insert the base agent info into
agent_cardswithtype=1andRETURNING card_id. - Insert the extended info (videos, kb details) into
dynamic_agent_detailsusing the returnedcard_id. - Return the new
card_id.
- Insert the base agent info into
-
Get Dynamic Agent Details
GET /dynamic_agent/{card_id}- Logic:
- Fetch base info from
agent_cards. - Fetch extended info from
dynamic_agent_details. - Return combined result.
- Fetch base info from
Helper Functions
init_dynamic_agent_db(): Checks/Creates thedynamic_agent_detailstable on startup.
3. Verification
- Create a dynamic agent via the new API.
- Verify it appears in the
agent_cardstable (as type 1). - Verify extended data is in
dynamic_agent_details.