cherry-studio/src/main/services/agents
MyPrototypeWhat b6dcf2f5fa
Feat/add skill tool (#11051)
* feat: add SkillTool component and integrate into agent tools

- Introduced SkillTool component for rendering skill-related functionality.
- Updated MessageAgentTools to include SkillTool in the tool renderers.
- Enhanced MessageTool to recognize 'Skill' as a valid agent tool type.
- Modified handleUserMessage to conditionally handle text blocks based on skill inclusion.
- Added SkillToolInput and SkillToolOutput types for better type safety.

* feat: implement command tag filtering in message handling

- Added filterCommandTags function to remove command-* tags from text content, ensuring internal command messages do not appear in the user-facing UI.
- Updated handleUserMessage to utilize the new filtering logic, enhancing the handling of text blocks and improving user experience by preventing unwanted command messages from being displayed.

* refactor: rename tool prefix constants for clarity

- Updated variable names for tool prefixes in MessageTool and SkillTool components to enhance code readability.
- Changed `prefix` to `builtinToolsPrefix` and `agentPrefix` to `agentMcpToolsPrefix` for better understanding of their purpose.
2025-10-31 16:31:50 +08:00
..
database feat: refactor message persistence and block update logic for agent sessions 2025-09-23 03:18:17 +08:00
interfaces Refactor/agent align (#10276) 2025-09-20 16:56:53 +08:00
plugins 🐛 fix: resolve tool approval UI and shared workspace plugin inconsistency (#11043) 2025-10-31 14:30:50 +08:00
services Feat/add skill tool (#11051) 2025-10-31 16:31:50 +08:00
BaseService.ts ♻️ refactor(agents): improve error handling and logging in agent services 2025-09-30 17:17:56 +08:00
drizzle.config.ts feat: Implement database migration system and update agent/session handling 2025-09-17 14:59:08 +08:00
errors.ts 💄 style: format code with yarn format 2025-09-21 16:44:54 +08:00
index.ts feat(agents): implement model validation for agent and session creation/updating 2025-09-19 20:20:20 +08:00
README.md feat(agents): implement model validation for agent and session creation/updating 2025-09-19 20:20:20 +08:00

Agents Service

Simplified Drizzle ORM implementation for agent and session management in Cherry Studio.

Features

  • Native Drizzle migrations - Uses built-in migrate() function
  • Zero CLI dependencies in production
  • Auto-initialization with retry logic
  • Full TypeScript type safety
  • Model validation to ensure models exist and provider configuration matches the agent type

Schema

  • agents.schema.ts - Agent definitions
  • sessions.schema.ts - Session and message tables
  • migrations.schema.ts - Migration tracking

Usage

import { agentService } from './services'

// Create agent - fully typed
const agent = await agentService.createAgent({
  type: 'custom',
  name: 'My Agent',
  model: 'anthropic:claude-3-5-sonnet-20241022'
})

Model Validation

  • Model identifiers must use the provider:model_id format (for example anthropic:claude-3-5-sonnet-20241022).
  • model, plan_model, and small_model are validated against the configured providers before the database is touched.
  • Invalid configurations return a 400 invalid_request_error response and the create/update operation is aborted.

Development Commands

# Apply schema changes
yarn agents:generate

# Quick development sync
yarn agents:push

# Database tools
yarn agents:studio    # Open Drizzle Studio
yarn agents:health    # Health check
yarn agents:drop      # Reset database

Workflow

  1. Edit schema in /database/schema/
  2. Generate migration with yarn agents:generate
  3. Test changes with yarn agents:health
  4. Deploy - migrations apply automatically

Services

  • AgentService - Agent CRUD operations
  • SessionService - Session management
  • SessionMessageService - Message logging
  • BaseService - Database utilities
  • schemaSyncer - Migration handler

Troubleshooting

# Check status
yarn agents:health

# Apply migrations
yarn agents:migrate

# Reset completely
yarn agents:reset --yes

The simplified migration system reduced complexity from 463 to ~30 lines while maintaining all functionality through Drizzle's native migration system.