From f7b8e970b29aff665e801a65309c9b56d3ac7d6a Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 12 Jan 2026 11:02:15 +0800 Subject: [PATCH 01/12] Refactor Logging in Request Render Method - Removed the dependency on the color package for logging warnings about uncached pages. - Simplified the logging statement to directly use the log package, improving code clarity and reducing unnecessary imports. --- sui/api/request.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sui/api/request.go b/sui/api/request.go index a8f1e9cf..a49716f2 100644 --- a/sui/api/request.go +++ b/sui/api/request.go @@ -9,7 +9,6 @@ import ( "strings" "time" - "github.com/fatih/color" "github.com/gin-gonic/gin" jsoniter "github.com/json-iterator/go" "github.com/yaoapp/gou/application" @@ -94,9 +93,7 @@ func (r *Request) Render() (string, int, error) { if c == nil { - message := fmt.Sprintf("[SUI] The page %s is not cached. file=%s DisableCache=%v", r.Request.URL.Path, r.File, r.Request.DisableCache()) - go fmt.Println(color.YellowString(message)) - go log.Warn("%s", message) + go log.Warn("[SUI] The page %s is not cached. file=%s DisableCache=%v", r.Request.URL.Path, r.File, r.Request.DisableCache()) var status int var err error From ce7996b982b803e5dc7aa75e98bd71bd1645ea78 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 08:47:54 +0800 Subject: [PATCH 02/12] Enhance Design Document with Trigger Sources Configuration - Added a new section detailing the configuration of trigger sources for AI members, including default settings and an example YAML configuration. - Updated the execution flow diagram to reflect the configurable nature of trigger sources, incorporating a check for trigger enablement. - Refactored the AI member configuration structure to include a dedicated triggers section, improving clarity and organization of the configuration options. --- agent/autonomous/DESIGN.md | 317 ++++++++++++++++++++----------------- 1 file changed, 168 insertions(+), 149 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index 3d32f01f..7c4569cb 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -920,17 +920,44 @@ func (r *ExecutionRequest) CalculatePriority(config *ManagerConfig, agentConfig ## Execution Flow +### Trigger Sources Configuration + +Trigger sources can be configured per AI member. All triggers are **enabled by default**. + +| Trigger Type | Config Field | Description | Default | +| ------------ | ---------------------------- | -------------------------------------- | ------- | +| Schedule | `triggers.schedule.enabled` | World Clock trigger (cron/interval) | `true` | +| Intervene | `triggers.intervene.enabled` | Human intervention trigger | `true` | +| Event | `triggers.event.enabled` | External event trigger (webhook, etc.) | `true` | + +**Configuration Example:** + +```yaml +agent_config: + triggers: + schedule: { enabled: true } + intervene: { enabled: true, actions: ["add_task", "pause"] } + event: { enabled: false } + + schedule: + type: cron + expr: "0 9 * * 1-5" + tz: Asia/Shanghai + timeout: 30m +``` + ### Execution Flow Diagram (Mermaid) ```mermaid flowchart TB - subgraph Trigger["Trigger Sources"] - WC[/"World Clock
(Schedule)"/] - HI[/"Human Intervention
(Intervene)"/] - EV[/"External Events
(Event)"/] + subgraph Trigger["Trigger Sources (Configurable)"] + WC[/"World Clock
(Schedule)
triggers.schedule"/] + HI[/"Human Intervention
(Intervene)
triggers.intervene"/] + EV[/"External Events
(Event)
triggers.event"/] end subgraph Manager["Autonomous Agent Manager"] + TriggerCheck{"Trigger
Enabled?"} Cache[("Agent Cache
(Memory)")] Check{Schedule Check
& Dedup} Queue["Global Queue
(Priority Sorted)"] @@ -990,10 +1017,12 @@ flowchart TB Job[("Job System
(Activity Monitor)")] end - %% Trigger to Manager - WC --> Cache - HI --> Cache - EV --> Cache + %% Trigger to Manager (with trigger enabled check) + WC --> TriggerCheck + HI --> TriggerCheck + EV --> TriggerCheck + TriggerCheck -->|Enabled| Cache + TriggerCheck -->|Disabled| X[/"Ignored"/] Cache --> Check Check -->|Pass| Queue Check -->|Duplicate/Skip| Cache @@ -1206,97 +1235,92 @@ Each Autonomous Agent executes the following standard flow when scheduling condi ### Agent Configuration (stored in team_members.agent_config) ```go -// AgentConfig AI member configuration (stored in team_members.agent_config JSON field) -type AgentConfig struct { - // Scheduling configuration - Schedule *Schedule `json:"schedule"` - - // Identity settings - Identity *Identity `json:"identity"` - - // Concurrency quota - Concurrency *ConcurrencyConfig `json:"concurrency"` - - // Private knowledge base (Agent exclusive, for self-learning) - PrivateKB *PrivateKB `json:"private_kb"` - - // Shared knowledge base (optional, team-shared knowledge) - SharedKB *SharedKB `json:"shared_kb,omitempty"` - - // Available resources - Resources *Resources `json:"resources"` - - // Delivery configuration - Delivery *Delivery `json:"delivery"` +// Config AI member configuration (stored in team_members.agent_config JSON field) +type Config struct { + Triggers *Triggers `json:"triggers,omitempty"` // Trigger sources (all enabled by default) + Schedule *Schedule `json:"schedule,omitempty"` // Schedule config (for cron/interval) + Identity *Identity `json:"identity"` // Role & responsibilities + Quota *Quota `json:"quota"` // Concurrency quota + PrivateKB *KB `json:"private_kb"` // Private knowledge base + SharedKB *KB `json:"shared_kb,omitempty"` // Shared knowledge base + Resources *Resources `json:"resources"` // Available assistants & tools + Delivery *Delivery `json:"delivery"` // Output delivery config } -// ConcurrencyConfig concurrency quota configuration -type ConcurrencyConfig struct { - MaxConcurrent int `json:"max_concurrent"` // Max concurrent executions for this member (default: 2) - QueueSize int `json:"queue_size"` // Queue size (default: 10) - Priority int `json:"priority"` // Scheduling priority (1-10, default: 5) +// Triggers trigger sources configuration (all enabled by default) +type Triggers struct { + Schedule *Trigger `json:"schedule,omitempty"` // World Clock + Intervene *Trigger `json:"intervene,omitempty"` // Human Intervention + Event *Trigger `json:"event,omitempty"` // External Events } -// Schedule scheduling configuration +// Trigger single trigger configuration +type Trigger struct { + Enabled bool `json:"enabled"` // default: true + Actions []string `json:"actions,omitempty"` // Allowed actions (for intervene only) +} + +// Quota concurrency quota +type Quota struct { + Max int `json:"max"` // Max concurrent (default: 2) + Queue int `json:"queue"` // Queue size (default: 10) + Priority int `json:"priority"` // Priority 1-10 (default: 5) +} + +// Schedule timing configuration type Schedule struct { - Type string `json:"type"` // cron | interval - Expression string `json:"expression"` // cron: "0 9 * * 1-5" or interval: "1h" - Timezone string `json:"timezone"` // Timezone - MaxExecutionTime string `json:"max_execution_time"` // Max execution time + Type string `json:"type"` // cron | interval + Expr string `json:"expr"` // "0 9 * * 1-5" or "1h" + TZ string `json:"tz"` // Timezone + Timeout string `json:"timeout"` // Max execution time } -// Identity identity settings +// Identity role settings type Identity struct { - Role string `json:"role"` // Role name - Responsibilities []string `json:"responsibilities"` // Responsibility list - Constraints []string `json:"constraints"` // Constraints + Role string `json:"role"` // Role name + Duties []string `json:"duties"` // Responsibilities + Rules []string `json:"rules"` // Constraints } -// PrivateKB Agent private knowledge base (auto-created, for self-learning) -type PrivateKB struct { - CollectionID string `json:"collection_id"` // KB collection ID (auto-generated: agent_{agent_id}_kb) - - // Learning configuration - Learning *LearningConfig `json:"learning,omitempty"` +// KB knowledge base configuration +type KB struct { + ID string `json:"id,omitempty"` // Collection ID (auto-gen for private) + Refs []string `json:"refs,omitempty"` // Referenced collections (for shared) + Learning *Learn `json:"learn,omitempty"` // Learning config (for private) } -// LearningConfig learning configuration -type LearningConfig struct { - Enabled bool `json:"enabled"` // Enable self-learning - Categories []string `json:"categories"` // Learning categories: ["execution", "feedback", "insight"] - RetentionDays int `json:"retention_days"` // Knowledge retention days, 0 means permanent +// Learn self-learning configuration +type Learn struct { + On bool `json:"on"` // Enable learning + Types []string `json:"types"` // ["execution", "feedback", "insight"] + Keep int `json:"keep"` // Retention days, 0 = forever } -// SharedKB shared knowledge base (optional, references team or global knowledge) -type SharedKB struct { - Collections []string `json:"collections"` // Referenced KB collection list -} - -// Resources available resources +// Resources available assistants & tools type Resources struct { - // Phase assistants (built-in or custom) - Inspiration string `json:"inspiration"` // Inspiration Agent (Phase 0) - GoalGenerator string `json:"goal_generator"` // Goal generation assistant (Phase 1) - TaskPlanner string `json:"task_planner"` // Task planning assistant (Phase 2) - Validator string `json:"validator"` // Result validation assistant (Phase 3) - Delivery string `json:"delivery"` // Delivery assistant (Phase 4) - Learning string `json:"learning"` // Learning assistant (Phase 5) + // Phase agents (P0-P5) + P0 string `json:"p0"` // Inspiration + P1 string `json:"p1"` // Goal Generator + P2 string `json:"p2"` // Task Planner + P3 string `json:"p3"` // Validator + P4 string `json:"p4"` // Delivery + P5 string `json:"p5"` // Learning // Execution resources - Assistants []string `json:"assistants"` // Callable assistant list - MCP []MCPServerConfig `json:"mcp"` // Callable MCP services + Agents []string `json:"agents"` // Callable assistants + MCP []MCP `json:"mcp"` // MCP services } -// MCPServerConfig MCP service configuration -type MCPServerConfig struct { - ServerID string `json:"server_id"` - Tools []string `json:"tools"` // Available tools list, empty means all +// MCP server configuration +type MCP struct { + ID string `json:"id"` + Tools []string `json:"tools,omitempty"` // empty = all } -// Delivery delivery configuration +// Delivery output configuration type Delivery struct { - Type string `json:"type"` // email | file | webhook | notification - Config map[string]interface{} `json:"config"` // Type-specific configuration + Type string `json:"type"` // email | file | webhook | notify + Opts map[string]interface{} `json:"opts"` // Type-specific options } ``` @@ -1626,46 +1650,46 @@ POST /api/teams/:team_id/members "agent_id": "sales-bot", "role_id": "analyst", "agent_config": { + "triggers": { + "schedule": { "enabled": true }, + "intervene": { "enabled": true }, + "event": { "enabled": false } + }, "schedule": { "type": "cron", - "expression": "0 9 * * 1-5", - "timezone": "Asia/Shanghai", - "max_execution_time": "30m" + "expr": "0 9 * * 1-5", + "tz": "Asia/Shanghai", + "timeout": "30m" }, "identity": { "role": "Sales Analyst", - "responsibilities": ["Analyze sales data", "Generate weekly reports"], - "constraints": ["Only access sales-related data"] + "duties": ["Analyze sales data", "Generate weekly reports"], + "rules": ["Only access sales-related data"] }, - "concurrency": { - "max_concurrent": 2, - "queue_size": 10, + "quota": { + "max": 2, + "queue": 10, "priority": 5 }, "private_kb": { - "learning": { - "enabled": true, - "categories": ["execution", "feedback", "insight"], - "retention_days": 90 - } + "learn": { "on": true, "types": ["execution", "feedback", "insight"], "keep": 90 } }, "shared_kb": { - "collections": ["sales-policies", "product-catalog"] + "refs": ["sales-policies", "product-catalog"] }, "resources": { - "goal_generator": "__yao.goal-generator", - "task_planner": "__yao.task-planner", - "validator": "__yao.validator", - "delivery": "__yao.report-generator", - "learning": "__yao.learning", - "assistants": ["data-analyst", "chart-generator"], - "mcp": [ - {"server_id": "database", "tools": ["query"]} - ] + "p0": "__yao.inspiration", + "p1": "__yao.goal-gen", + "p2": "__yao.task-plan", + "p3": "__yao.validator", + "p4": "__yao.delivery", + "p5": "__yao.learning", + "agents": ["data-analyst", "chart-gen"], + "mcp": [{ "id": "database", "tools": ["query"] }] }, "delivery": { "type": "email", - "config": {"recipients": ["manager@company.com"]} + "opts": { "to": ["manager@company.com"] } } } } @@ -2204,61 +2228,56 @@ agent_config: priority: 5 # Execution priority (affects queue sorting) ``` -## Complete AgentConfig Structure +## Complete Config Structure ```go -// AgentConfig AI member complete configuration -type AgentConfig struct { - // Scheduling configuration - Schedule *Schedule `json:"schedule"` - - // Identity settings - Identity *Identity `json:"identity"` - - // Concurrency quota - Concurrency *ConcurrencyConfig `json:"concurrency"` - - // Private knowledge base - PrivateKB *PrivateKB `json:"private_kb"` - - // Shared knowledge base - SharedKB *SharedKB `json:"shared_kb,omitempty"` - - // Available resources - Resources *Resources `json:"resources"` - - // Delivery configuration - Delivery *Delivery `json:"delivery"` - - // Input configuration (isolation, strategies) - Input *InputConfig `json:"input,omitempty"` - - // Event source configuration - EventSources []EventSource `json:"event_sources,omitempty"` - - // Monitoring configuration - Monitoring *MonitoringConfig `json:"monitoring,omitempty"` +// Config AI member complete configuration +type Config struct { + Triggers *Triggers `json:"triggers,omitempty"` // Trigger sources (all enabled by default) + Schedule *Schedule `json:"schedule,omitempty"` // Timing config + Identity *Identity `json:"identity"` // Role & duties + Quota *Quota `json:"quota"` // Concurrency quota + PrivateKB *KB `json:"private_kb"` // Private KB + SharedKB *KB `json:"shared_kb,omitempty"` // Shared KB refs + Resources *Resources `json:"resources"` // Agents & tools + Delivery *Delivery `json:"delivery"` // Output config + Input *Input `json:"input,omitempty"` // Input isolation + Events []Event `json:"events,omitempty"` // Event sources + Monitor *Monitor `json:"monitor,omitempty"` // Monitoring } -// MonitoringConfig monitoring configuration -type MonitoringConfig struct { - Enabled bool `json:"enabled"` - Alerts []AlertRule `json:"alerts,omitempty"` +// Triggers trigger sources (all enabled by default) +type Triggers struct { + Schedule *Trigger `json:"schedule,omitempty"` + Intervene *Trigger `json:"intervene,omitempty"` + Event *Trigger `json:"event,omitempty"` } -// AlertRule alert rule definition -type AlertRule struct { - Name string `json:"name"` // Rule name - Condition string `json:"condition"` // Trigger condition: "execution_failed" | "timeout" | "error_rate_high" - Threshold float64 `json:"threshold"` // Threshold value (e.g., error rate > 0.1) - Window string `json:"window"` // Time window (e.g., "1h", "24h") - Actions []AlertAction `json:"actions"` // Actions to take when triggered - Cooldown string `json:"cooldown"` // Cooldown period between alerts +// Trigger single trigger config +type Trigger struct { + Enabled bool `json:"enabled"` + Actions []string `json:"actions,omitempty"` // For intervene only } -// AlertAction alert action -type AlertAction struct { - Type string `json:"type"` // "email" | "webhook" | "notification" - Config map[string]interface{} `json:"config"` // Action-specific configuration +// Monitor monitoring config +type Monitor struct { + On bool `json:"on"` + Alerts []Alert `json:"alerts,omitempty"` +} + +// Alert rule definition +type Alert struct { + Name string `json:"name"` // Rule name + When string `json:"when"` // failed | timeout | error_rate + Value float64 `json:"value"` // Threshold + Window string `json:"window"` // 1h | 24h + Do []Action `json:"do"` // Actions + Cooldown string `json:"cooldown"` // Cooldown period +} + +// Action alert action +type Action struct { + Type string `json:"type"` // email | webhook | notify + Opts map[string]interface{} `json:"opts"` } ``` From 1d5881fe5fe885613308e6596b55ead8914d1f21 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 08:52:59 +0800 Subject: [PATCH 03/12] Refactor Autonomous Agent Design Document for Clarity and Structure - Revised the document to enhance clarity by reorganizing sections and improving terminology, such as changing "Core Features" to "Key Characteristics." - Introduced a new architecture section detailing the system's trigger sources and their integration with the agent manager. - Updated the execution flow and lifecycle diagrams to reflect the new structure and added detailed descriptions for each phase of the agent's operation. - Enhanced the configuration section to include a comprehensive overview of triggers, scheduling, and resource management, improving the overall organization of the document. --- agent/autonomous/DESIGN.md | 2700 ++++++++---------------------------- 1 file changed, 573 insertions(+), 2127 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index 7c4569cb..c41d61eb 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -1,1273 +1,353 @@ # Autonomous Agent Design Document -## Overview +## 1. Overview -An Autonomous Agent is an **AI member** within a team, belonging to a Team just like human members. From the user's perspective, it's simply a team member with clearly defined job responsibilities (such as Sales Manager, Data Analyst, Customer Service Representative, etc.). It can operate independently, make autonomous decisions, and execute tasks. Unlike Assistants that passively respond to user requests, Autonomous Agents are proactive, capable of running periodically based on job responsibilities and rules to complete complex multi-step tasks. +An **Autonomous Agent** is an AI team member that operates independently, makes decisions, and executes tasks proactively. Unlike Assistants that respond to user requests, Autonomous Agents run periodically based on job responsibilities. -**Core Features:** +**Key Characteristics:** -- **Team Member**: From the user's perspective, it's an AI member managed like human members -- **Job Responsibilities**: Each AI member has clearly defined duties and knows what to do -- **Dynamic Lifecycle**: Dynamically created/destroyed based on team needs -- **Autonomous Operation**: Triggered by the World Clock, periodically executing job responsibilities +- **Team Member**: Managed like human members, belongs to a Team +- **Job Responsibilities**: Has defined duties (e.g., "Sales Manager tracks KPIs") +- **Dynamic Lifecycle**: Created/destroyed via Team API +- **Multi-Trigger**: Activated by schedule, human intervention, or events +- **Self-Learning**: Maintains private knowledge base, learns from execution -## Relationship with Team +--- -From the user's perspective, an Autonomous Agent is an **AI member** within the team. Each AI member has clearly defined job responsibilities, and a Team can have multiple AI members. +## 2. Architecture + +### 2.1 System Overview + +```mermaid +flowchart TB + subgraph Triggers["Trigger Sources"] + WC[/"โฐ World Clock
(Schedule)"/] + HI[/"๐Ÿ‘ค Human
(Intervene)"/] + EV[/"๐Ÿ“ก Events
(Webhook/DB)"/] + end + + subgraph Manager["Agent Manager"] + TC{"Trigger
Enabled?"} + Cache[("Agent Cache")] + Dedup{"Dedup
Check"} + Queue["Priority Queue"] + end + + subgraph Pool["Worker Pool"] + W1["Worker"] + W2["Worker"] + W3["Worker"] + end + + subgraph Executor["Executor"] + P0["P0: Inspiration"] + P1["P1: Goals"] + P2["P2: Tasks"] + P3["P3: Execute"] + P4["P4: Deliver"] + P5["P5: Learn"] + end + + subgraph Storage["Storage"] + KB[("Private KB")] + DB[("Executions")] + Job[("Job System")] + end + + WC & HI & EV --> TC + TC -->|Yes| Cache + TC -->|No| X[/Ignored/] + Cache --> Dedup + Dedup -->|Pass| Queue + Dedup -->|Skip| Cache + Queue --> W1 & W2 & W3 + W1 & W2 & W3 --> P0 + P0 --> P1 --> P2 --> P3 --> P4 --> P5 + P5 --> KB & DB & Job + KB -.->|Experience| P0 +``` + +### 2.2 Team Integration + +AI members are stored in `team_members` table with `member_type = "ai"`: ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Team โ”‚ -โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ AI Members โ”‚ โ”‚ +โ”‚ โ”‚ AI Members โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚Sales Managerโ”‚ โ”‚Data Analyst โ”‚ โ”‚CS Specialistโ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ (AI Member) โ”‚ โ”‚ (AI Member) โ”‚ โ”‚ (AI Member) โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ Duties: โ”‚ โ”‚ Duties: โ”‚ โ”‚ Duties: โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Track KPIsโ”‚ โ”‚ โ€ข Analyze โ”‚ โ”‚ โ€ข Handle โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ€ข Generate โ”‚ โ”‚ data โ”‚ โ”‚ tickets โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ reports โ”‚ โ”‚ โ€ข Generate โ”‚ โ”‚ โ€ข Reply to โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ reports โ”‚ โ”‚ inquiries โ”‚ โ”‚ โ”‚ +โ”‚ โ”‚ โ”‚ โ€ข Track KPIsโ”‚ โ”‚ โ€ข Analyze โ”‚ โ”‚ โ€ข Tickets โ”‚ โ”‚ โ”‚ +โ”‚ โ”‚ โ”‚ โ€ข Reports โ”‚ โ”‚ โ€ข Reports โ”‚ โ”‚ โ€ข Inquiries โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Human Members โ”‚ โ”‚ +โ”‚ โ”‚ Human Members โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ John โ”‚ โ”‚ Jane โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ (Owner) โ”‚ โ”‚ (Admin) โ”‚ โ”‚ โ”‚ +โ”‚ โ”‚ โ”‚ John (Owner)โ”‚ โ”‚ Jane (Admin)โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` -### Team Member Table Extension - -AI members reuse the `team_members` table, distinguished by `member_type`: - ```sql --- team_members table CREATE TABLE team_members ( id BIGINT PRIMARY KEY AUTO_INCREMENT, team_id VARCHAR(64) NOT NULL, - user_id VARCHAR(64), -- user_id for human members + user_id VARCHAR(64), -- Human members member_type VARCHAR(32) NOT NULL, -- "user" | "ai" - role_id VARCHAR(64), - - -- AI member specific fields - agent_id VARCHAR(64), -- Autonomous Agent ID (AI members only) - agent_config JSON, -- Agent configuration (identity, resources, delivery, etc.) - - is_owner BOOLEAN DEFAULT FALSE, + agent_id VARCHAR(64), -- AI members only + agent_config JSON, -- AI config status VARCHAR(32) DEFAULT 'active', - joined_at DATETIME, - created_at DATETIME, - updated_at DATETIME, - INDEX idx_team_id (team_id), - INDEX idx_member_type (member_type), INDEX idx_agent_id (agent_id) ); ``` -## System Architecture +--- -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ World Clock โ”‚ -โ”‚ (Global timer, e.g., every minute) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ Tick - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Autonomous Agent Manager โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ โ€ข Get active AI members from memory cache โ”‚ โ”‚ -โ”‚ โ”‚ (loaded at startup, refreshed on changes) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Check scheduling conditions โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Execution-level deduplication (prevent duplicate โ”‚ โ”‚ -โ”‚ โ”‚ submissions) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Dispatch execution requests to eligible members โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Monitor execution status, handle failures and retries โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Team A โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ AI: Sales Mgr โ”‚ โ”‚ AI: Analyst โ”‚ โ”‚ AI: Editor โ”‚ โ”‚ -โ”‚ โ”‚ (sales-manager) โ”‚ โ”‚ (data-analyst) โ”‚ โ”‚ (content-editor)โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Duties: โ”‚ โ”‚ Duties: โ”‚ โ”‚ Duties: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Track sales โ”‚ โ”‚ โ€ข Analyze data โ”‚ โ”‚ โ€ข Generate โ”‚ โ”‚ -โ”‚ โ”‚ performance โ”‚ โ”‚ โ€ข Generate โ”‚ โ”‚ marketing โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Generate โ”‚ โ”‚ analysis โ”‚ โ”‚ content โ”‚ โ”‚ -โ”‚ โ”‚ sales reports โ”‚ โ”‚ reports โ”‚ โ”‚ โ€ข Maintain KB โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Human: John โ”‚ โ”‚ Human: Jane โ”‚ โ”‚ -โ”‚ โ”‚ (owner) โ”‚ โ”‚ (admin) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` +## 3. How It Works -## Core Design Philosophy - -### 1. AI Member = Team Member with Job Responsibilities - -Each Autonomous Agent is simply an **AI member** to the user, but internally has clearly defined job responsibilities: - -- **Job Responsibilities**: Clearly knows what to do (e.g., "Sales Manager tracks performance and generates reports") -- **Resource Permissions**: Accessible resources and callable tools are defined by configuration -- **Private Knowledge Base**: Dedicated KB for accumulating work experience and expertise -- **Goal-Driven**: Autonomously generates work goals based on job responsibilities -- **Task Execution**: Breaks down goals into specific tasks, calls Assistants/MCP Tools to execute -- **Result Delivery**: Generates deliverables (reports, emails, notifications, etc.) -- **Continuous Learning**: Learns from execution to continuously improve capabilities - -### 2. Multi-Trigger Source Concurrent Execution - -The same AI member can be triggered in multiple ways, supporting concurrent execution: - -- **World Clock**: Scheduled triggers (cron/interval) -- **Human Intervention**: Manually add tasks, adjust goals -- **Event Triggers**: webhooks, database changes, etc. - -> **Note**: Agent-to-agent collaboration (one Agent calling another Agent) is implemented at the Assistant layer, not part of the scheduling layer's responsibility. - -### 3. Concurrency Control and Resource Quotas - -To prevent resources from being monopolized by a single member, the system implements two-level control: - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Global Worker Pool โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Total Workers: 10 (configurable) โ”‚ โ”‚ -โ”‚ โ”‚ Currently Used: 6 โ”‚ โ”‚ -โ”‚ โ”‚ Queued Tasks: 3 โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ–ผ โ–ผ โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Sales Manager โ”‚ โ”‚ Data Analyst โ”‚ โ”‚ CS Specialist โ”‚ -โ”‚ Quota: 3 โ”‚ โ”‚ Quota: 2 โ”‚ โ”‚ Quota: 3 โ”‚ -โ”‚ Current: 2 โœ“ โ”‚ โ”‚ Current: 2(full)โ”‚ โ”‚ Current: 2 โœ“ โ”‚ -โ”‚ Queued: 1 โ”‚ โ”‚ Queued: 2 โ”‚ โ”‚ Queued: 0 โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -**Two-Level Control:** - -1. **Global Worker Pool**: Limits total system concurrency, shared by all members -2. **Member Quota**: Maximum concurrent executions per member, prevents single member from monopolizing resources - -### 4. Member Cache (Avoiding Frequent DB Queries) - -Manager loads all active members into memory at startup, refreshes via events: - -```go -// AgentCache member cache -type AgentCache struct { - agents map[string]*AutonomousAgent // agent_id -> agent - byTeam map[string][]string // team_id -> []agent_id - mutex sync.RWMutex - lastLoad time.Time -} - -// Cache refresh timing -// 1. Full load at Manager startup -// 2. Incremental refresh on member create/update/delete (via event notification) -// 3. Periodic full refresh (e.g., hourly, as fallback) - -func (c *AgentCache) Refresh(agentID string) { - // Load single member from database, update cache -} - -func (c *AgentCache) RefreshAll() { - // Full refresh -} - -func (c *AgentCache) GetActive() []*AutonomousAgent { - // Return all active members (from memory, no database query) -} -``` - -### 5. Deduplication - -Uses **Agent semantic understanding** for deduplication, determining duplicates based on historical task data: - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Deduplication Service โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Core idea: Let Agent determine "has this task been done โ”‚ โ”‚ -โ”‚ โ”‚ before" โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Input: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Goal/task to be evaluated โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Historical execution records (retrieved from DB) โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Output: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข is_duplicate: whether it's a duplicate โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข reason: reasoning for the judgment โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข similar_task_id: ID of similar historical task โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -**Deduplication Approach:** - -```go -// DeduplicationService deduplication service -type DeduplicationService struct { - dedupAgent string // Dedup Agent ID (e.g., __yao.dedup-checker) -} - -// DedupRequest deduplication request -type DedupRequest struct { - AgentID string `json:"agent_id"` - Type string `json:"type"` // goal | task - Content string `json:"content"` // goal/task description - Context interface{} `json:"context"` // context information -} - -// DedupResult deduplication result -type DedupResult struct { - IsDuplicate bool `json:"is_duplicate"` - Confidence float64 `json:"confidence"` // confidence 0-1 - Reason string `json:"reason"` // reasoning - SimilarID string `json:"similar_id"` // similar historical record ID - SimilarDesc string `json:"similar_desc"` // similar record description - Suggestion string `json:"suggestion"` // suggestion (skip | merge | proceed) -} -``` - -**Agent Semantic Deduplication Flow:** - -``` -Goal/Task to be checked - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Step 1: Retrieve Historical Records โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Query from database for this member's recent: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Goal records (last 7 days) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Task records (last 24 hours) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Execution results (success/failure/in-progress) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Step 2: Agent Semantic Judgment โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Call Dedup Agent with Prompt: โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ "Please determine if the following goal duplicates โ”‚ โ”‚ -โ”‚ โ”‚ historical records: โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Goal to check: {content} โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Historical records: โ”‚ โ”‚ -โ”‚ โ”‚ 1. [2024-01-09] Analyze weekly sales data - Completed โ”‚ โ”‚ -โ”‚ โ”‚ 2. [2024-01-08] Generate customer analysis - Completed โ”‚ โ”‚ -โ”‚ โ”‚ 3. [2024-01-10] Track key customers - In progress โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Please determine: โ”‚ โ”‚ -โ”‚ โ”‚ - Is it essentially the same as any historical record? โ”‚ โ”‚ -โ”‚ โ”‚ - If so, suggest how to handle (skip/merge/proceed)?" โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Step 3: Decision Based on Result โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ โ€ข skip: Skip, don't execute โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข merge: Merge into existing task โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข proceed: Continue execution (not duplicate, or needs โ”‚ โ”‚ -โ”‚ โ”‚ re-execution) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -**Dedup Agent Implementation:** - -```go -// Call Dedup Agent for semantic judgment -func (s *DeduplicationService) CheckDuplicate(ctx *context.Context, req *DedupRequest) (*DedupResult, error) { - - // 1. Retrieve historical records - var history []HistoryRecord - switch req.Type { - case "goal": - history = s.getRecentGoals(req.AgentID, 7*24*time.Hour) - case "task": - history = s.getRecentTasks(req.AgentID, 24*time.Hour) - } - - // If no historical records, return not duplicate - if len(history) == 0 { - return &DedupResult{IsDuplicate: false, Suggestion: "proceed"}, nil - } - - // 2. Build dedup prompt - prompt := buildDedupPrompt(req.Content, history) - - // 3. Call Dedup Agent - messages := []context.Message{ - {Role: "system", Content: dedupSystemPrompt}, - {Role: "user", Content: prompt}, - } - - response, err := s.callAgent(ctx, s.dedupAgent, messages) - if err != nil { - // On dedup failure, default to not blocking execution - return &DedupResult{IsDuplicate: false, Suggestion: "proceed"}, nil - } - - // 4. Parse Agent's structured response - return parseDedupResponse(response) -} - -// Dedup Agent system prompt -var dedupSystemPrompt = `You are a task deduplication assistant. Your job is to determine if a new task duplicates historical tasks. - -Judgment criteria: -1. Essentially the same: The core intent of the goal/task is the same, even if worded differently -2. Time sensitivity: Consider if the task is time-sensitive (e.g., "today's report" vs "yesterday's report" are not duplicates) -3. Execution status: If a historical task failed, it may need re-execution - -Output format (JSON): -{ - "is_duplicate": true/false, - "confidence": 0.0-1.0, - "reason": "reasoning", - "similar_id": "similar historical record ID, if any", - "suggestion": "skip | merge | proceed" -} - -Suggestion meanings: -- skip: Complete duplicate, suggest skipping -- merge: Partial duplicate, suggest merging into existing task -- proceed: Not duplicate, or similar but needs re-execution` -``` - -**Deduplication Timing:** - -| Phase | Dedup Type | Description | -| ---------------- | --------------- | ------------------------------------------------------------------- | -| After Phase 1 | Goal dedup | Compare generated goals with historical goals | -| After Phase 2 | Task dedup | Compare decomposed tasks with historical tasks | -| Before execution | Execution dedup | Prevent same trigger from duplicate submission (memory-level, fast) | - -**Execution-Level Deduplication (Fast, Memory):** - -```go -// Execution-level dedup (no Agent needed, pure memory check) -type ExecutionDedup struct { - runningSet map[string]bool // agent_id + trigger_type + trigger_id - queuedSet map[string]bool - mutex sync.RWMutex -} - -func (d *ExecutionDedup) IsDuplicate(agentID, triggerType, triggerID string) bool { - key := fmt.Sprintf("%s:%s:%s", agentID, triggerType, triggerID) - d.mutex.RLock() - defer d.mutex.RUnlock() - return d.runningSet[key] || d.queuedSet[key] -} -``` - -### 6. Inspiration Factor - -The Inspiration Factor is input on the executing Agent side, collected in **Phase 0** by calling a dedicated **Inspiration Agent**. - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Execution Start (Executor Side) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Phase 0: Inspiration Collection โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Call: Inspiration Agent (dedicated inspiration collector)โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Input: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Member identity info (job responsibilities) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข List of accessible data sources โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Last execution time โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Private knowledge base ID โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Inspiration Agent Responsibilities: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Query data sources, discover changes โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Check time factors (periodic tasks, deadlines) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Retrieve historical experience (success/failure โ”‚ โ”‚ -โ”‚ โ”‚ patterns) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Get pending items โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Web Search: Perceive external world changes related โ”‚ โ”‚ -โ”‚ โ”‚ to job responsibilities โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Comprehensive analysis, generate inspiration report โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Output: InspirationReport โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - Phase 1: Goal Generation - (Use inspiration report to generate high-value goals) -``` - -**Inspiration Agent Configuration:** - -```go -// Configured in AgentConfig.Resources -type Resources struct { - // Phase assistants - Inspiration string `json:"inspiration"` // Inspiration Agent (Phase 0) - GoalGenerator string `json:"goal_generator"` // Goal Generator Agent (Phase 1) - TaskPlanner string `json:"task_planner"` // Task Planner Agent (Phase 2) - Validator string `json:"validator"` // Validator Agent (Phase 3) - Delivery string `json:"delivery"` // Delivery Agent (Phase 4) - Learning string `json:"learning"` // Learning Agent (Phase 5) - - // ... -} -``` - -**Inspiration Report Structure:** - -```go -// InspirationReport (generated by Inspiration Agent) -type InspirationReport struct { - // Structured output from Agent analysis - Summary string `json:"summary"` // Overall situation summary - Highlights []Highlight `json:"highlights"` // Key findings - Opportunities []Opportunity `json:"opportunities"` // Discovered opportunities - Risks []Risk `json:"risks"` // Potential risks - WorldInsights []WorldInsight `json:"world_insights"` // External world insights - Suggestions []string `json:"suggestions"` // Suggested focus areas - - // Raw data (for Goal Generator reference) - RawData *InspirationData `json:"raw_data"` -} - -// Highlight key finding -type Highlight struct { - Type string `json:"type"` // data_change | event | feedback | deadline | world_news - Title string `json:"title"` // Title - Description string `json:"description"` // Description - Importance string `json:"importance"` // high | medium | low - Source string `json:"source"` // internal | external -} - -// Opportunity -type Opportunity struct { - Description string `json:"description"` - Reason string `json:"reason"` // Why it's an opportunity - TimeWindow string `json:"time_window"` // Time window - Source string `json:"source"` // internal | external -} - -// Risk -type Risk struct { - Description string `json:"description"` - Impact string `json:"impact"` // Impact - Mitigation string `json:"mitigation"` // Suggested mitigation - Source string `json:"source"` // internal | external -} - -// WorldInsight external world insight -type WorldInsight struct { - Topic string `json:"topic"` // Topic - Insight string `json:"insight"` // Insight - ActionSuggestion string `json:"action_suggestion"` // Suggested action -} - -// InspirationData raw inspiration data -type InspirationData struct { - // Internal changes (system data) - DataChanges []DataChange `json:"data_changes"` - Events []Event `json:"events"` - Feedbacks []Feedback `json:"feedbacks"` - - // External world changes (Web Search) - WorldNews []WorldNews `json:"world_news"` - - // Time factors - TimeContext *TimeContext `json:"time_context"` - Deadlines []Deadline `json:"deadlines"` - - // Historical experience - RecentGoals []GoalRecord `json:"recent_goals"` - - // Pending items - PendingItems []PendingItem `json:"pending_items"` -} - -// WorldNews external world news -type WorldNews struct { - Topic string `json:"topic"` // Search topic (based on job responsibilities) - Title string `json:"title"` // News/update title - Summary string `json:"summary"` // Summary - Source string `json:"source"` // Source - URL string `json:"url"` // Link - PublishedAt time.Time `json:"published_at"` // Published time - Relevance float64 `json:"relevance"` // Relevance to job (0-1) -} - -// DataChange data change -type DataChange struct { - Source string `json:"source"` // Data source - ChangeType string `json:"change_type"` // insert | update | threshold - Description string `json:"description"` // Change description - Timestamp time.Time `json:"timestamp"` -} - -// TimeContext time context -type TimeContext struct { - Now time.Time `json:"now"` - DayOfWeek string `json:"day_of_week"` // Monday, Tuesday... - IsWeekend bool `json:"is_weekend"` - IsMonthStart bool `json:"is_month_start"` - IsMonthEnd bool `json:"is_month_end"` - IsQuarterEnd bool `json:"is_quarter_end"` - // Extensible: holidays, special dates, etc. -} -``` - -**Inspiration Agent Call:** - -```go -// Phase 0: Call Inspiration Agent to collect inspiration -func (e *Executor) collectInspiration(ctx *context.Context, agent *AutonomousAgent) (*InspirationReport, error) { - - // 1. Prepare raw data (collected by system, provided to Agent) - rawData := &InspirationData{ - // Internal data changes - DataChanges: e.dataMonitor.GetChanges(agent.AgentID, agent.LastExecutionTime), - Events: e.eventQueue.GetPending(agent.AgentID), - Feedbacks: e.feedbackStore.GetRecent(agent.AgentID), - - // External world news (Web Search) - WorldNews: e.searchWorldNews(agent.Config.Identity), - - // Time and history - TimeContext: buildTimeContext(time.Now()), - Deadlines: e.getUpcomingDeadlines(agent.AgentID), - RecentGoals: e.getRecentGoals(agent.AgentID), - PendingItems: e.getPendingItems(agent.AgentID), - } - -// searchWorldNews searches for external world news related to job responsibilities -func (e *Executor) searchWorldNews(identity *Identity) []WorldNews { - // 1. Generate search keywords based on job responsibilities - keywords := e.generateSearchKeywords(identity) - - // 2. Call Web Search MCP Tool - var news []WorldNews - for _, keyword := range keywords { - results, err := e.mcpClient.Call("web_search", map[string]interface{}{ - "query": keyword, - "limit": 5, - "recent": "24h", // Only search last 24 hours - }) - if err != nil { - continue - } - - // 3. Filter and evaluate relevance - for _, r := range results { - news = append(news, WorldNews{ - Topic: keyword, - Title: r.Title, - Summary: r.Snippet, - Source: r.Source, - URL: r.URL, - PublishedAt: r.PublishedAt, - Relevance: e.evaluateRelevance(r, identity), - }) - } - } - - // 4. Sort by relevance, take Top N - sort.Slice(news, func(i, j int) bool { - return news[i].Relevance > news[j].Relevance - }) - if len(news) > 10 { - news = news[:10] - } - - return news -} - - // 2. Build prompt for Inspiration Agent to analyze - prompt := buildInspirationPrompt(agent.Config.Identity, rawData) - - messages := []context.Message{ - {Role: "system", Content: inspirationSystemPrompt}, - {Role: "user", Content: prompt}, - } - - // 3. Call Inspiration Agent - response, err := e.callAssistant(ctx, agent.Config.Resources.Inspiration, messages) - if err != nil { - return nil, err - } - - // 4. Parse returned inspiration report - report := parseInspirationReport(response) - report.RawData = rawData - - return report, nil -} - -// Inspiration Agent system prompt -var inspirationSystemPrompt = `You are an inspiration collection assistant. Your job is to analyze the current situation and discover valuable work directions for AI members. - -You will receive: -1. The member's job responsibilities -2. Recent data changes, events, feedback -3. External world news (industry news, market changes related to the job) -4. Time context (day of week, end of month, etc.) -5. Historical goal execution status -6. Pending items - -Please analyze this information and output a structured inspiration report (JSON): -{ - "summary": "One-sentence summary of the overall situation", - "highlights": [ - {"type": "data_change|event|feedback|deadline|world_news", "title": "Title", "description": "Description", "importance": "high|medium|low"} - ], - "opportunities": [ - {"description": "Opportunity description", "reason": "Why it's an opportunity", "time_window": "Time window", "source": "internal|external"} - ], - "risks": [ - {"description": "Risk description", "impact": "Impact", "mitigation": "Suggested measures", "source": "internal|external"} - ], - "world_insights": [ - {"topic": "Topic", "insight": "Insight", "action_suggestion": "Suggested action"} - ], - "suggestions": ["Suggested focus area 1", "Suggested focus area 2"] -} - -Key points: -- Identify important changes and anomalies (internal data + external world) -- Discover potential opportunities (combined with industry trends) -- Alert potential risks (including risks from external environment changes) -- Extract job-relevant insights from external world news -- Give suggestions based on time factors` -``` - -**Injecting Inspiration Report into Goal Generation:** - -```go -// Phase 1: Generate goals using inspiration report -func (e *Executor) generateGoals(ctx *context.Context, agent *AutonomousAgent, report *InspirationReport) ([]Goal, error) { - - // Build goal generation prompt, inject inspiration report - prompt := buildGoalPrompt(agent.Config.Identity, report) - - /* - Prompt example: - - You are [Sales Manager], responsible for [tracking sales performance, generating reports]. - - ## Inspiration Report - - ### Summary - This week's sales data shows significant changes, and there are new industry developments to focus on. - - ### Key Findings - - [High] Data change: 15 new sales records yesterday, 50% increase - - [High] Deadline: Today is Friday, need to prepare weekly report - - [Medium] Customer feedback: Customer A submitted product feedback - - [High] External news: Competitor released new product, may affect market landscape - - ### Opportunities - - [Internal] This week's sales exceeded last week by 20%, can analyze growth reasons - - [Internal] TOP3 customers contributed 60% of sales, worth deep analysis - - [External] Industry report shows market demand growth, opportunity to expand - - ### Risks - - [Internal] 3 days until month end, monthly target only 80% complete - - [External] Competitor price promotion, need to watch for customer churn risk - - ### External World Insights - - Topic: Industry Trends - Insight: AI adoption in sales accelerating, automation tool demand growing - Suggestion: Evaluate automation opportunities in current sales process - - Topic: Competitors - Insight: XX company released new product line, focusing on value - Suggestion: Prepare differentiation strategy, emphasize service advantages - - ### Suggested Directions - - Analyze this week's sales growth reasons - - Prepare weekly report - - Follow up on monthly target progress - - Monitor competitor developments, prepare response strategy - - Please generate today's most valuable work goals based on the above inspiration report. - */ - - messages := []context.Message{ - {Role: "system", Content: goalGeneratorSystemPrompt}, - {Role: "user", Content: prompt}, - } - - return e.callAssistant(ctx, agent.Config.Resources.GoalGenerator, messages) -} -``` - -**Manager-Side Tick Processing Flow:** - -```go -func (m *Manager) onTick() { - // Get active members from cache (no database query) - agents := m.cache.GetActive() - - for _, agent := range agents { - // 1. Check scheduling time - if !agent.ShouldRun(time.Now()) { - continue - } - - // 2. Execution-level deduplication (fast, memory) - dedupKey := fmt.Sprintf("%s:schedule:%s", agent.AgentID, getScheduleWindow(time.Now())) - if m.executionDedup.IsDuplicate(dedupKey) { - continue - } - - // 3. Build execution request (no inspiration factor, collected on Executor side) - req := &ExecutionRequest{ - AgentID: agent.AgentID, - TriggerType: "schedule", - TriggerTime: time.Now(), - } - - // 4. Submit to scheduler - m.scheduler.Submit(req) - } -} -``` - -**Executor-Side Execution Flow:** - -```go -func (e *Executor) Execute(ctx *context.Context, req *ExecutionRequest, agent *AutonomousAgent) (*ExecutionState, error) { - state := &ExecutionState{ - AgentID: agent.AgentID, - StartTime: time.Now(), - Status: StatusRunning, - } - - // Phase 0: Inspiration collection (call Inspiration Agent) - state.Phase = PhaseInspiration - report, err := e.collectInspiration(ctx, agent) - if err != nil { - // Inspiration collection failure doesn't block execution, use empty report - report = &InspirationReport{Summary: "Inspiration collection failed, using default mode"} - } - - // Phase 1: Goal generation (using inspiration report) - state.Phase = PhaseGoalGeneration - goals, err := e.generateGoals(ctx, agent, report) - if err != nil { - return state.Failed(err) - } - - // Phase 1.5: Goal deduplication (call Dedup Agent) - goals, err = e.deduplicateGoals(ctx, agent, goals) - if err != nil { - return state.Failed(err) - } - state.Goals = goals - - // Phase 2: Task decomposition - state.Phase = PhaseTaskDecomposition - tasks, err := e.decomposeTasks(ctx, agent, goals) - if err != nil { - return state.Failed(err) - } - - // Phase 2.5: Task deduplication (call Dedup Agent) - tasks, err = e.deduplicateTasks(ctx, agent, tasks) - if err != nil { - return state.Failed(err) - } - state.Tasks = tasks - - // Phase 3: Task execution - state.Phase = PhaseTaskExecution - for i := range tasks { - if err := e.executeTask(ctx, agent, &tasks[i]); err != nil { - tasks[i].Status = TaskStatusFailed - tasks[i].Error = err.Error() - } - } - - // Phase 4: Result delivery - state.Phase = PhaseDelivery - if err := e.deliver(ctx, agent, state); err != nil { - // Delivery failure is recorded but doesn't interrupt - state.DeliveryError = err.Error() - } - - // Phase 5: Learning - state.Phase = PhaseLearning - if err := e.learn(ctx, agent, state); err != nil { - // Learning failure is recorded but doesn't interrupt - } - - state.Status = StatusCompleted - state.EndTime = time.Now() - return state, nil -} -``` - -### Scheduling Flow - -``` -Trigger Source (World Clock/Human Intervention/Event) - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Scheduler โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ 1. Check member quota: current concurrent < max? โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Yes โ†’ Enter global queue โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข No โ†’ Enter member wait queue โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ 2. Global queue sorted by priority โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Member priority โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Trigger time (FIFO) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Trigger type weight (intervention > event > schedule)โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Global Worker Pool โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Worker gets task: โ”‚ โ”‚ -โ”‚ โ”‚ 1. Take highest priority task from global queue โ”‚ โ”‚ -โ”‚ โ”‚ 2. Double check member quota โ”‚ โ”‚ -โ”‚ โ”‚ 3. Execute task, update member concurrent count โ”‚ โ”‚ -โ”‚ โ”‚ 4. On completion, release and check member wait queue โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -### Global Configuration - -```go -// ManagerConfig global manager configuration -type ManagerConfig struct { - // Worker pool configuration - GlobalWorkerCount int `json:"global_worker_count"` // Global worker count (default: 10) - GlobalQueueSize int `json:"global_queue_size"` // Global queue size (default: 100) - - // Default member quota (can be overridden by member config) - DefaultMaxConcurrent int `json:"default_max_concurrent"` // Default max concurrent (default: 2) - DefaultQueueSize int `json:"default_queue_size"` // Default queue size (default: 10) - - // Trigger type weights (for priority sorting) - TriggerWeights map[string]int `json:"trigger_weights"` // intervene: 100, event: 50, schedule: 10 -} -``` - -### Execution Request - -```go -// ExecutionRequest execution request -type ExecutionRequest struct { - ID string `json:"id"` - AgentID string `json:"agent_id"` - TeamID string `json:"team_id"` - TriggerType string `json:"trigger_type"` // schedule | intervene | event - TriggerData interface{} `json:"trigger_data"` // Trigger-related data - Priority int `json:"priority"` // Calculated priority - CreatedAt time.Time `json:"created_at"` - Status string `json:"status"` // queued | running | completed | failed -} - -// Priority calculation -func (r *ExecutionRequest) CalculatePriority(config *ManagerConfig, agentConfig *AgentConfig) int { - // Base priority = member priority - priority := agentConfig.Concurrency.Priority * 10 - - // + trigger type weight - if weight, ok := config.TriggerWeights[r.TriggerType]; ok { - priority += weight - } - - // + wait time bonus (every minute waiting +1) - waitMinutes := int(time.Since(r.CreatedAt).Minutes()) - priority += waitMinutes - - return priority -} -``` - -## Execution Flow - -### Trigger Sources Configuration - -Trigger sources can be configured per AI member. All triggers are **enabled by default**. - -| Trigger Type | Config Field | Description | Default | -| ------------ | ---------------------------- | -------------------------------------- | ------- | -| Schedule | `triggers.schedule.enabled` | World Clock trigger (cron/interval) | `true` | -| Intervene | `triggers.intervene.enabled` | Human intervention trigger | `true` | -| Event | `triggers.event.enabled` | External event trigger (webhook, etc.) | `true` | - -**Configuration Example:** - -```yaml -agent_config: - triggers: - schedule: { enabled: true } - intervene: { enabled: true, actions: ["add_task", "pause"] } - event: { enabled: false } - - schedule: - type: cron - expr: "0 9 * * 1-5" - tz: Asia/Shanghai - timeout: 30m -``` - -### Execution Flow Diagram (Mermaid) - -```mermaid -flowchart TB - subgraph Trigger["Trigger Sources (Configurable)"] - WC[/"World Clock
(Schedule)
triggers.schedule"/] - HI[/"Human Intervention
(Intervene)
triggers.intervene"/] - EV[/"External Events
(Event)
triggers.event"/] - end - - subgraph Manager["Autonomous Agent Manager"] - TriggerCheck{"Trigger
Enabled?"} - Cache[("Agent Cache
(Memory)")] - Check{Schedule Check
& Dedup} - Queue["Global Queue
(Priority Sorted)"] - end - - subgraph WorkerPool["Global Worker Pool"] - W1["Worker 1"] - W2["Worker 2"] - W3["Worker N..."] - end - - subgraph Executor["Agent Executor"] - subgraph Phase0["Phase 0: Inspiration"] - P0_1["Collect Internal Data Changes"] - P0_2["Web Search: External World"] - P0_3["Call Inspiration Agent"] - P0_4[/"Inspiration Report"/] - end - - subgraph Phase1["Phase 1: Goal Generation"] - P1_1["Inject Inspiration Report"] - P1_2["Call Goal Generator Agent"] - P1_3["Goal Deduplication"] - P1_4[/"Goals List"/] - end - - subgraph Phase2["Phase 2: Task Decomposition"] - P2_1["Analyze Goals"] - P2_2["Call Task Planner Agent"] - P2_3["Task Deduplication"] - P2_4[/"Tasks List"/] - end - - subgraph Phase3["Phase 3: Task Execution"] - P3_1["Execute Task via Assistant/MCP"] - P3_2["Call Validator Agent"] - P3_3{All Tasks
Complete?} - P3_4[/"Task Results"/] - end - - subgraph Phase4["Phase 4: Delivery"] - P4_1["Aggregate Results"] - P4_2["Call Delivery Agent"] - P4_3[/"Deliverables
(Email/Report/File)"/] - end - - subgraph Phase5["Phase 5: Learning"] - P5_1["Analyze Execution"] - P5_2["Call Learning Agent"] - P5_3["Write to Private KB"] - end - end - - subgraph Storage["Persistence"] - KB[("Private KB")] - DB[("autonomous_executions")] - Job[("Job System
(Activity Monitor)")] - end - - %% Trigger to Manager (with trigger enabled check) - WC --> TriggerCheck - HI --> TriggerCheck - EV --> TriggerCheck - TriggerCheck -->|Enabled| Cache - TriggerCheck -->|Disabled| X[/"Ignored"/] - Cache --> Check - Check -->|Pass| Queue - Check -->|Duplicate/Skip| Cache - - %% Manager to Worker - Queue --> W1 - Queue --> W2 - Queue --> W3 - - %% Worker to Executor - W1 --> Phase0 - W2 --> Phase0 - W3 --> Phase0 - - %% Phase 0 Flow - P0_1 --> P0_3 - P0_2 --> P0_3 - P0_3 --> P0_4 - - %% Phase 1 Flow - P0_4 --> P1_1 - P1_1 --> P1_2 - P1_2 --> P1_3 - P1_3 --> P1_4 - - %% Phase 2 Flow - P1_4 --> P2_1 - P2_1 --> P2_2 - P2_2 --> P2_3 - P2_3 --> P2_4 - - %% Phase 3 Flow - P2_4 --> P3_1 - P3_1 --> P3_2 - P3_2 --> P3_3 - P3_3 -->|No| P3_1 - P3_3 -->|Yes| P3_4 - - %% Phase 4 Flow - P3_4 --> P4_1 - P4_1 --> P4_2 - P4_2 --> P4_3 - - %% Phase 5 Flow - P4_3 --> P5_1 - P5_1 --> P5_2 - P5_2 --> P5_3 - - %% Storage connections - P5_3 --> KB - P5_3 --> DB - P5_3 --> Job - - %% KB feedback to Phase 0 - KB -.->|Historical Experience| P0_1 -``` - -### Execution Sequence Diagram (Mermaid) +### 3.1 Trigger โ†’ Schedule โ†’ Execute ```mermaid sequenceDiagram autonumber - participant WC as World Clock + participant T as Trigger participant M as Manager participant S as Scheduler participant W as Worker participant E as Executor - participant IA as Inspiration Agent - participant GA as Goal Agent - participant TA as Task Planner - participant VA as Validator - participant DA as Delivery Agent - participant LA as Learning Agent + participant A as Agents (P0-P5) participant KB as Private KB - participant Job as Job System - WC->>M: Tick Event - M->>M: Get active agents from cache - M->>M: Check schedule & dedup - M->>S: Submit ExecutionRequest + T->>M: Trigger Event + M->>M: Check trigger enabled + M->>M: Get agent from cache + M->>M: Dedup check + M->>S: Submit request - S->>S: Check member quota - S->>S: Priority queue sorting - S->>W: Dispatch to worker + S->>S: Check quota + S->>S: Priority sort + S->>W: Dispatch - W->>E: Execute(agent) - E->>Job: Create Execution record + W->>E: Execute - rect rgb(240, 248, 255) - Note over E,IA: Phase 0: Inspiration Collection - E->>E: Collect data changes - E->>E: Web search for world news - E->>IA: Analyze & generate report - IA-->>E: InspirationReport + loop Phase 0-5 + E->>A: Call phase agent + A-->>E: Result end - rect rgb(255, 250, 240) - Note over E,GA: Phase 1: Goal Generation - E->>KB: Retrieve historical experience - KB-->>E: Past goals & insights - E->>GA: Generate goals (with inspiration) - GA-->>E: Goals[] - E->>E: Deduplicate goals - end - - rect rgb(240, 255, 240) - Note over E,TA: Phase 2: Task Decomposition - E->>TA: Decompose goals into tasks - TA-->>E: Tasks[] - E->>E: Deduplicate tasks - end - - rect rgb(255, 240, 245) - Note over E,VA: Phase 3: Task Execution - loop For each task - E->>E: Execute via Assistant/MCP - E->>VA: Validate result - VA-->>E: Validation result - E->>Job: Update progress - end - end - - rect rgb(245, 245, 255) - Note over E,DA: Phase 4: Delivery - E->>DA: Generate deliverables - DA-->>E: Email/Report/File - end - - rect rgb(255, 255, 240) - Note over E,LA: Phase 5: Learning - E->>LA: Analyze execution - LA-->>E: Knowledge entries - E->>KB: Store learned knowledge - end - - E->>Job: Complete Execution - E-->>W: ExecutionState - W-->>S: Release worker - S-->>M: Execution complete + E->>KB: Store learning + E-->>W: Complete ``` -### Phase Details +### 3.2 Trigger Sources -Each Autonomous Agent executes the following standard flow when scheduling conditions are met: +| Trigger | Description | Config | +| ------------- | --------------------------- | -------------------- | +| **Schedule** | World Clock (cron/interval) | `triggers.schedule` | +| **Intervene** | Human intervention | `triggers.intervene` | +| **Event** | Webhook, DB changes | `triggers.event` | + +All triggers enabled by default. Configure per-agent: + +```yaml +triggers: + schedule: { enabled: true } + intervene: { enabled: true, actions: ["add_task", "pause"] } + event: { enabled: false } +``` + +### 3.3 Concurrency Control + +Two-level control prevents resource monopolization: ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Autonomous Agent Execution โ”‚ -โ”‚ โ”‚ -โ”‚ Input: Identity + Private KB + Current State โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Phase 1: Goal Generation โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Call: Goal Generator Assistant โ”‚ โ”‚ -โ”‚ โ”‚ Input: Identity + Private KB + Historical Context โ”‚ โ”‚ -โ”‚ โ”‚ Output: Goal list (with priorities) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Phase 2: Task Decomposition โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Call: Task Planner Assistant โ”‚ โ”‚ -โ”‚ โ”‚ Input: Goal list + Available resources (Agents/MCP Tools)โ”‚ โ”‚ -โ”‚ โ”‚ Output: Task list (with dependencies and executor โ”‚ โ”‚ -โ”‚ โ”‚ assignments) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Phase 3: Task Execution โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Loop through each task: โ”‚ โ”‚ -โ”‚ โ”‚ 1. Call specified Agent or MCP Tool to execute task โ”‚ โ”‚ -โ”‚ โ”‚ 2. Collect execution results โ”‚ โ”‚ -โ”‚ โ”‚ 3. Call Validator Assistant to verify results โ”‚ โ”‚ -โ”‚ โ”‚ 4. Update task status โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Phase 4: Delivery โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Call: Delivery Assistant โ”‚ โ”‚ -โ”‚ โ”‚ Input: All task results + Delivery config โ”‚ โ”‚ -โ”‚ โ”‚ Output: Final deliverables (email/report/file/ โ”‚ โ”‚ -โ”‚ โ”‚ notification, etc.) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Phase 5: Learning (Self-Learning) โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Call: Learning Assistant โ”‚ โ”‚ -โ”‚ โ”‚ Input: Execution process + Results + Feedback โ”‚ โ”‚ -โ”‚ โ”‚ Output: Experience summary โ†’ Write to Private KB โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ +โ”‚ Global Worker Pool (10 workers) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ”‚ โ”‚ โ”‚ + โ–ผ โ–ผ โ–ผ +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ Sales Manager โ”‚ โ”‚ Data Analyst โ”‚ โ”‚ CS Specialist โ”‚ +โ”‚ Quota: 3 โ”‚ โ”‚ Quota: 2 โ”‚ โ”‚ Quota: 3 โ”‚ +โ”‚ Current: 2 โœ“ โ”‚ โ”‚ Current: 2 (full)โ”‚ โ”‚ Current: 1 โœ“ โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` -## Data Structures +### 3.4 Deduplication -### Agent Configuration (stored in team_members.agent_config) +**Execution-level** (fast, memory): + +```go +key := fmt.Sprintf("%s:%s:%s", agentID, triggerType, window) +if cache.Has(key) { skip } +``` + +**Semantic-level** (Agent-based, for goals/tasks): + +- Dedup Agent analyzes historical records +- Returns: `skip` | `merge` | `proceed` + +### 3.5 Agent Cache + +Avoids frequent DB queries: + +```go +type AgentCache struct { + agents map[string]*Agent // agent_id -> agent + byTeam map[string][]string // team_id -> []agent_id +} + +// Refresh: startup, on change, periodic (hourly) +``` + +--- + +## 4. Execution Phases + +### 4.1 Phase Overview + +``` +P0: Inspiration โ†’ P1: Goals โ†’ P2: Tasks โ†’ P3: Execute โ†’ P4: Deliver โ†’ P5: Learn +``` + +| Phase | Agent | Input | Output | +| ----- | -------------- | -------------------------------------- | ----------------- | +| P0 | Inspiration | Data changes, world news, time context | InspirationReport | +| P1 | Goal Generator | Inspiration + KB experience | Goals[] | +| P2 | Task Planner | Goals + available resources | Tasks[] | +| P3 | Validator | Task results | Validated results | +| P4 | Delivery | All results | Email/Report/File | +| P5 | Learning | Execution summary | KB entries | + +### 4.2 Phase 0: Inspiration + +Collects context to generate high-value goals: + +```go +type InspirationReport struct { + Summary string // Overall situation + Highlights []Highlight // Key findings (data_change|event|deadline|world_news) + Opportunities []Opportunity // Discovered opportunities + Risks []Risk // Potential risks + WorldInsights []WorldInsight // External world insights + Suggestions []string // Focus areas +} +``` + +**Data sources:** + +- Internal: Data changes, events, feedback, pending items +- External: Web search (industry news, competitors) +- Time: Day of week, month end, deadlines + +### 4.3 Phase 1: Goal Generation + +Uses inspiration report to generate goals: + +``` +Prompt: +You are [Sales Manager], responsible for [tracking KPIs, generating reports]. + +## Inspiration Report +### Key Findings +- [High] Data: 15 new sales records (+50%) +- [High] Deadline: Friday, prepare weekly report +- [High] External: Competitor launched new product + +### Opportunities +- Sales exceeded last week by 20% +- Industry report shows market growth + +Please generate today's most valuable work goals. +``` + +### 4.4 Phase 2: Task Decomposition + +Breaks goals into executable tasks: + +```go +type Task struct { + ID string + GoalID string + Description string + ExecutorType string // "assistant" | "mcp" + ExecutorID string // Assistant ID or MCP tool +} +``` + +### 4.5 Phase 3: Execution + +For each task: + +1. Call specified Assistant or MCP Tool +2. Collect result +3. Call Validator to verify +4. Update status + +### 4.6 Phase 4: Delivery + +Generates deliverables based on config: + +```yaml +delivery: + type: email # email | file | webhook | notify + opts: + to: ["manager@company.com"] +``` + +### 4.7 Phase 5: Learning + +Analyzes execution, writes to private KB: + +| Category | Examples | +| ----------- | ----------------------------------- | +| `execution` | Task process, success/failure cases | +| `feedback` | Validation results, error analysis | +| `insight` | Patterns, optimization suggestions | + +--- + +## 5. Configuration + +### 5.1 Config Structure ```go -// Config AI member configuration (stored in team_members.agent_config JSON field) type Config struct { - Triggers *Triggers `json:"triggers,omitempty"` // Trigger sources (all enabled by default) - Schedule *Schedule `json:"schedule,omitempty"` // Schedule config (for cron/interval) - Identity *Identity `json:"identity"` // Role & responsibilities - Quota *Quota `json:"quota"` // Concurrency quota - PrivateKB *KB `json:"private_kb"` // Private knowledge base - SharedKB *KB `json:"shared_kb,omitempty"` // Shared knowledge base - Resources *Resources `json:"resources"` // Available assistants & tools - Delivery *Delivery `json:"delivery"` // Output delivery config + Triggers *Triggers `json:"triggers,omitempty"` // Trigger sources + Schedule *Schedule `json:"schedule,omitempty"` // Timing + Identity *Identity `json:"identity"` // Role & duties + Quota *Quota `json:"quota"` // Concurrency + PrivateKB *KB `json:"private_kb"` // Private KB + SharedKB *KB `json:"shared_kb,omitempty"` // Shared KB refs + Resources *Resources `json:"resources"` // Agents & tools + Delivery *Delivery `json:"delivery"` // Output + Input *Input `json:"input,omitempty"` // Input isolation + Events []Event `json:"events,omitempty"` // Event sources + Monitor *Monitor `json:"monitor,omitempty"` // Monitoring } +``` -// Triggers trigger sources configuration (all enabled by default) +### 5.2 Type Definitions + +```go +// Triggers (all enabled by default) type Triggers struct { - Schedule *Trigger `json:"schedule,omitempty"` // World Clock - Intervene *Trigger `json:"intervene,omitempty"` // Human Intervention - Event *Trigger `json:"event,omitempty"` // External Events + Schedule *Trigger `json:"schedule,omitempty"` + Intervene *Trigger `json:"intervene,omitempty"` + Event *Trigger `json:"event,omitempty"` } -// Trigger single trigger configuration type Trigger struct { - Enabled bool `json:"enabled"` // default: true - Actions []string `json:"actions,omitempty"` // Allowed actions (for intervene only) + Enabled bool `json:"enabled"` + Actions []string `json:"actions,omitempty"` // For intervene only } -// Quota concurrency quota -type Quota struct { - Max int `json:"max"` // Max concurrent (default: 2) - Queue int `json:"queue"` // Queue size (default: 10) - Priority int `json:"priority"` // Priority 1-10 (default: 5) -} - -// Schedule timing configuration +// Schedule type Schedule struct { Type string `json:"type"` // cron | interval Expr string `json:"expr"` // "0 9 * * 1-5" or "1h" @@ -1275,443 +355,307 @@ type Schedule struct { Timeout string `json:"timeout"` // Max execution time } -// Identity role settings +// Identity type Identity struct { - Role string `json:"role"` // Role name + Role string `json:"role"` // Role name Duties []string `json:"duties"` // Responsibilities - Rules []string `json:"rules"` // Constraints + Rules []string `json:"rules"` // Constraints } -// KB knowledge base configuration +// Quota +type Quota struct { + Max int `json:"max"` // Max concurrent (default: 2) + Queue int `json:"queue"` // Queue size (default: 10) + Priority int `json:"priority"` // 1-10 (default: 5) +} + +// KB type KB struct { - ID string `json:"id,omitempty"` // Collection ID (auto-gen for private) - Refs []string `json:"refs,omitempty"` // Referenced collections (for shared) - Learning *Learn `json:"learn,omitempty"` // Learning config (for private) + ID string `json:"id,omitempty"` // Collection ID + Refs []string `json:"refs,omitempty"` // Shared refs + Learn *Learn `json:"learn,omitempty"` // Learning config } -// Learn self-learning configuration type Learn struct { - On bool `json:"on"` // Enable learning - Types []string `json:"types"` // ["execution", "feedback", "insight"] - Keep int `json:"keep"` // Retention days, 0 = forever + On bool `json:"on"` // Enable + Types []string `json:"types"` // ["execution", "feedback", "insight"] + Keep int `json:"keep"` // Retention days, 0 = forever } -// Resources available assistants & tools +// Resources type Resources struct { - // Phase agents (P0-P5) - P0 string `json:"p0"` // Inspiration - P1 string `json:"p1"` // Goal Generator - P2 string `json:"p2"` // Task Planner - P3 string `json:"p3"` // Validator - P4 string `json:"p4"` // Delivery - P5 string `json:"p5"` // Learning - - // Execution resources + P0 string `json:"p0"` // Inspiration + P1 string `json:"p1"` // Goal Generator + P2 string `json:"p2"` // Task Planner + P3 string `json:"p3"` // Validator + P4 string `json:"p4"` // Delivery + P5 string `json:"p5"` // Learning Agents []string `json:"agents"` // Callable assistants MCP []MCP `json:"mcp"` // MCP services } -// MCP server configuration type MCP struct { ID string `json:"id"` Tools []string `json:"tools,omitempty"` // empty = all } -// Delivery output configuration +// Delivery type Delivery struct { Type string `json:"type"` // email | file | webhook | notify - Opts map[string]interface{} `json:"opts"` // Type-specific options + Opts map[string]interface{} `json:"opts"` +} + +// Monitor +type Monitor struct { + On bool `json:"on"` + Alerts []Alert `json:"alerts,omitempty"` +} + +type Alert struct { + Name string `json:"name"` + When string `json:"when"` // failed | timeout | error_rate + Value float64 `json:"value"` // Threshold + Window string `json:"window"` // 1h | 24h + Do []Action `json:"do"` + Cooldown string `json:"cooldown"` +} + +type Action struct { + Type string `json:"type"` // email | webhook | notify + Opts map[string]interface{} `json:"opts"` } ``` -### Execution State +### 5.3 Full Example -```go -// ExecutionState execution state (persisted to database) -type ExecutionState struct { - ID string `json:"id"` - TeamID string `json:"team_id"` - AgentID string `json:"agent_id"` - StartTime time.Time `json:"start_time"` - EndTime *time.Time `json:"end_time,omitempty"` - Status ExecutionStatus `json:"status"` - Phase ExecutionPhase `json:"phase"` - Goals []Goal `json:"goals,omitempty"` - Tasks []Task `json:"tasks,omitempty"` - Error string `json:"error,omitempty"` - DeliveryResult interface{} `json:"delivery_result,omitempty"` -} - -type ExecutionStatus string - -const ( - StatusPending ExecutionStatus = "pending" - StatusRunning ExecutionStatus = "running" - StatusCompleted ExecutionStatus = "completed" - StatusFailed ExecutionStatus = "failed" -) - -type ExecutionPhase string - -const ( - PhaseInspiration ExecutionPhase = "inspiration" // Phase 0 - PhaseGoalGeneration ExecutionPhase = "goal_generation" // Phase 1 - PhaseTaskDecomposition ExecutionPhase = "task_decomposition" // Phase 2 - PhaseTaskExecution ExecutionPhase = "task_execution" // Phase 3 - PhaseDelivery ExecutionPhase = "delivery" // Phase 4 - PhaseLearning ExecutionPhase = "learning" // Phase 5 -) - -// Goal -type Goal struct { - ID string `json:"id"` - Description string `json:"description"` - Priority int `json:"priority"` - Status string `json:"status"` -} - -// Task -type Task struct { - ID string `json:"id"` - GoalID string `json:"goal_id"` - Description string `json:"description"` - ExecutorType string `json:"executor_type"` // assistant | mcp - ExecutorID string `json:"executor_id"` - Status string `json:"status"` - Result interface{} `json:"result,omitempty"` - Error string `json:"error,omitempty"` +```json +{ + "member_type": "ai", + "agent_id": "sales-bot", + "agent_config": { + "triggers": { + "schedule": { "enabled": true }, + "intervene": { "enabled": true }, + "event": { "enabled": false } + }, + "schedule": { + "type": "cron", + "expr": "0 9 * * 1-5", + "tz": "Asia/Shanghai", + "timeout": "30m" + }, + "identity": { + "role": "Sales Analyst", + "duties": ["Analyze sales data", "Generate weekly reports"], + "rules": ["Only access sales-related data"] + }, + "quota": { "max": 2, "queue": 10, "priority": 5 }, + "private_kb": { + "learn": { + "on": true, + "types": ["execution", "feedback", "insight"], + "keep": 90 + } + }, + "shared_kb": { "refs": ["sales-policies", "product-catalog"] }, + "resources": { + "p0": "__yao.inspiration", + "p1": "__yao.goal-gen", + "p2": "__yao.task-plan", + "p3": "__yao.validator", + "p4": "__yao.delivery", + "p5": "__yao.learning", + "agents": ["data-analyst", "chart-gen"], + "mcp": [{ "id": "database", "tools": ["query"] }] + }, + "delivery": { + "type": "email", + "opts": { "to": ["manager@company.com"] } + } + } } ``` -## Core Interfaces +--- -### Manager Interface +## 6. Lifecycle + +### 6.1 State Diagram + +``` +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” POST create โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚ โ”‚ +โ”‚ None โ”‚ โ”‚ Active โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜ โ”‚ + โ”‚ โ”‚ + PATCH pause โ”‚ PATCH resume + โ–ผ โ”‚ + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ + โ”‚ Paused โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜ + โ”‚ + DELETE โ”‚ + โ–ผ + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” + โ”‚ Deleted โ”‚ + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +``` + +### 6.2 State Transitions + +| From | To | Trigger | +| ------------- | ------- | --------------------- | +| - | active | POST create member | +| active | paused | PATCH status="paused" | +| paused | active | PATCH status="active" | +| active/paused | deleted | DELETE member | + +### 6.3 Initialization + +On create: + +1. Validate config +2. Generate agent_id (if not provided) +3. Create private KB: `agent_{team_id}_{agent_id}_kb` +4. Register with Manager (add to cache) +5. Create Job entry +6. Set status = "active" + +### 6.4 Active State + +``` +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ Idle โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Triggeredโ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Running โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Learning โ”‚ +โ”‚ โ”‚โ—€โ”€โ”€โ”€โ”€โ”‚ โ”‚ โ”‚ (P0-P4) โ”‚ โ”‚ (P5) โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ + โ–ฒ โ”‚ + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +``` + +### 6.5 Termination + +On delete: + +1. Cancel running executions +2. Remove from cache +3. Delete Job entry +4. Handle KB (delete or archive) +5. Soft delete record + +--- + +## 7. Integrations + +### 7.1 Job System (Activity Monitor) + +Each Agent maps to a Job, each execution to an Execution: + +``` +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ Activity Monitor (UI) โ”‚ +โ”‚ โ€ข Task list and status โ”‚ +โ”‚ โ€ข Real-time progress โ”‚ +โ”‚ โ€ข Execution logs โ”‚ +โ”‚ โ€ข Cancel/pause/retry โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ”‚ + โ–ผ +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ Job Framework โ”‚ +โ”‚ Job โ†’ Execution โ†’ Progress โ†’ Logs โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +``` + +**APIs:** + +| Feature | API | +| ----------- | -------------------------------------------- | +| List agents | `GET /api/jobs?category_id=autonomous_agent` | +| History | `GET /api/jobs/:job_id/executions` | +| Progress | `GET /api/jobs/:job_id/executions/:id` | +| Logs | `GET /api/jobs/:job_id/executions/:id/logs` | +| Cancel | `POST /api/jobs/:job_id/stop` | +| Trigger | `POST /api/jobs/:job_id/trigger` | + +### 7.2 Private Knowledge Base + +Auto-created per agent: `agent_{team_id}_{agent_id}_kb` + +**Learning categories:** + +- `execution`: Task process, success/failure +- `feedback`: Validation, errors +- `insight`: Patterns, best practices + +**Lifecycle:** + +- Create: On agent creation +- Update: After each execution (P5) +- Cleanup: Based on `keep` config +- Delete: On agent deletion (or archive) + +### 7.3 External Input + +**Input types:** + +- `schedule`: World Clock +- `intervene`: Human intervention +- `event`: Webhooks, DB triggers +- `callback`: Async task callbacks + +**Intervention actions:** + +- `adjust_goal`: Modify current goal +- `add_task`: Add new task +- `cancel_task`: Cancel task +- `pause` / `resume` / `abort` +- `plan`: Queue for later + +**Plan Queue:** + +- Stores deferred goals/tasks +- Processed at start of next execution + +--- + +## 8. API Reference + +### 8.1 Core Interfaces ```go -// Manager Autonomous Agent manager type Manager interface { - // Start/stop world clock Start() error Stop() error - - // Load active AI members from database - LoadActiveAgents(ctx context.Context) ([]*AutonomousAgent, error) - - // Check if Agent should execute - ShouldExecute(agent *AutonomousAgent, now time.Time) bool - - // Execute single Agent - Execute(ctx context.Context, agent *AutonomousAgent) (*ExecutionState, error) - - // Manually trigger execution - Trigger(ctx context.Context, teamID, agentID string) (*ExecutionState, error) - - // Query execution history - GetExecutionHistory(ctx context.Context, teamID, agentID string, limit int) ([]*ExecutionState, error) + LoadActiveAgents(ctx context.Context) ([]*Agent, error) + ShouldExecute(agent *Agent, now time.Time) bool + Execute(ctx context.Context, agent *Agent) (*State, error) + Trigger(ctx context.Context, teamID, agentID string) (*State, error) + GetHistory(ctx context.Context, teamID, agentID string, limit int) ([]*State, error) } ``` -### AutonomousAgent Structure +### 8.2 Execution State ```go -// AutonomousAgent autonomous agent (loaded from database) -type AutonomousAgent struct { - // From team_members table - TeamID string `json:"team_id"` - AgentID string `json:"agent_id"` - RoleID string `json:"role_id"` - Status string `json:"status"` - - // From agent_config JSON - Config *AgentConfig `json:"config"` - - // Runtime state - LastExecutionTime *time.Time `json:"last_execution_time,omitempty"` +type State struct { + ID string + TeamID string + AgentID string + StartTime time.Time + EndTime *time.Time + Status Status // pending | running | completed | failed + Phase Phase // inspiration | goal_generation | task_decomposition | task_execution | delivery | learning + Goals []Goal + Tasks []Task + Error string + Result interface{} } ``` -## Private Knowledge Base and Self-Learning - -Each Autonomous Agent has a dedicated private knowledge base for storing learning outcomes and accumulated experience. - -### Automatic KB Creation - -When an AI member is created, the system automatically creates a private knowledge base: - -```go -// Auto-create private KB when creating AI member -func createAgentPrivateKB(teamID, agentID string) (string, error) { - collectionID := fmt.Sprintf("agent_%s_%s_kb", teamID, agentID) - - // Call KB API to create collection - err := kb.CreateCollection(collectionID, &kb.CollectionConfig{ - Name: fmt.Sprintf("Agent %s Private KB", agentID), - Description: "Auto-created private knowledge base for autonomous agent", - Type: "agent_private", - TeamID: teamID, - AgentID: agentID, - }) - - return collectionID, err -} -``` - -### Learning Content Categories - -The private knowledge base stores the following types of knowledge: - -| Category | Description | Examples | -| ----------- | ------------------------- | ------------------------------------------------------------- | -| `execution` | Execution records/results | Task execution process, success/failure cases | -| `feedback` | Feedback and evaluation | Validation results, user feedback, error analysis | -| `insight` | Insights and summaries | Pattern recognition, optimization suggestions, best practices | - -### Learning Flow (Phase 5) - -``` -After execution โ†’ Learning Assistant analyzes execution process - โ”‚ - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Analysis content: โ”‚ - โ”‚ โ€ข Goal achievementโ”‚ - โ”‚ โ€ข Task efficiency โ”‚ - โ”‚ โ€ข Errors/anomaliesโ”‚ - โ”‚ โ€ข Success patternsโ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Generate knowledgeโ”‚ - โ”‚ entries: โ”‚ - โ”‚ โ€ข Experience โ”‚ - โ”‚ summary โ”‚ - โ”‚ โ€ข Improvement โ”‚ - โ”‚ suggestions โ”‚ - โ”‚ โ€ข Cautions โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - Write to Private KB (vectorized storage) -``` - -### Knowledge Application - -In Phase 1 (Goal Generation), the Goal Generator Assistant retrieves from the private knowledge base: - -```go -// Retrieve relevant experience during goal generation -func (e *Executor) generateGoals(ctx *context.Context, agent *AutonomousAgent) ([]Goal, error) { - // 1. Build retrieval query - query := buildGoalQuery(agent.Config.Identity) - - // 2. Retrieve relevant experience from private KB - experiences, err := kb.Search(agent.Config.PrivateKB.CollectionID, query, &kb.SearchOptions{ - Categories: []string{"insight", "feedback"}, - Limit: 10, - }) - - // 3. Call Goal Generator Assistant, inject historical experience - messages := []context.Message{ - {Role: "system", Content: buildGoalPrompt(agent.Config.Identity, experiences)}, - {Role: "user", Content: "Please generate today's goals based on current state and historical experience"}, - } - - return e.callAssistant(ctx, agent.Config.Resources.GoalGenerator, messages) -} -``` - -### Knowledge Base Lifecycle - -- **Creation**: Auto-created when AI member is created -- **Update**: New knowledge written after each execution -- **Cleanup**: Auto-cleanup of expired knowledge based on `retention_days` config -- **Deletion**: When AI member is deleted, KB can be retained or deleted - -## Integration with Assistant - -Autonomous Agents complete various phase tasks by calling existing Assistants: - -```go -// Call Assistant example -func (e *Executor) callAssistant(ctx *context.Context, assistantID string, messages []context.Message) (*context.Response, error) { - ast, err := assistant.Get(assistantID) - if err != nil { - return nil, err - } - - return ast.Stream(ctx, messages, &context.Options{ - // Configuration options - }) -} -``` - -## Lifecycle Management - -### AI Member Lifecycle Diagram - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ AI Member Lifecycle โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Create โ”‚ POST /api/teams/:team_id/members - โ”‚ (member_type: "ai") - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Initialization โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ 1. Validate agent_config โ”‚ โ”‚ -โ”‚ โ”‚ 2. Generate agent_id (if not provided) โ”‚ โ”‚ -โ”‚ โ”‚ 3. Create private KB: agent_{team_id}_{agent_id}_kb โ”‚ โ”‚ -โ”‚ โ”‚ 4. Register with Manager (add to cache) โ”‚ โ”‚ -โ”‚ โ”‚ 5. Create Job entry for scheduling โ”‚ โ”‚ -โ”‚ โ”‚ 6. Set status = "active" โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Active State โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ Idle โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Triggeredโ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Running โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Learning โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚โ—€โ”€โ”€โ”€โ”€โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ -โ”‚ โ”‚ โ–ฒ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ Triggers: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข World Clock (schedule) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Human Intervention (intervene) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข External Events (event) โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”‚ PATCH /api/teams/:team_id/members/:member_id - โ”‚ (status: "paused") - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Paused State โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ โ€ข Removed from active cache โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข No longer triggered by World Clock โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Private KB preserved โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Can be resumed: PATCH status = "active" โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ”‚ DELETE /api/teams/:team_id/members/:member_id - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Termination โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ 1. Cancel running executions (if any) โ”‚ โ”‚ -โ”‚ โ”‚ 2. Remove from Manager cache โ”‚ โ”‚ -โ”‚ โ”‚ 3. Delete Job entry โ”‚ โ”‚ -โ”‚ โ”‚ 4. Handle private KB: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Option A: Delete KB (default) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Option B: Archive KB (if preserve_kb=true) โ”‚ โ”‚ -โ”‚ โ”‚ 5. Mark record as deleted (soft delete) โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Deleted โ”‚ - โ”‚ (archived) โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - - -State Transitions: -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ From โ”‚ To โ”‚ Trigger โ”‚ -โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค -โ”‚ - โ”‚ active โ”‚ POST create member โ”‚ -โ”‚ active โ”‚ paused โ”‚ PATCH status="paused" โ”‚ -โ”‚ paused โ”‚ active โ”‚ PATCH status="active" โ”‚ -โ”‚ active โ”‚ deleted โ”‚ DELETE member โ”‚ -โ”‚ paused โ”‚ deleted โ”‚ DELETE member โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -### Creating AI Member - -```go -// Add AI member via Team API -POST /api/teams/:team_id/members -{ - "member_type": "ai", - "agent_id": "sales-bot", - "role_id": "analyst", - "agent_config": { - "triggers": { - "schedule": { "enabled": true }, - "intervene": { "enabled": true }, - "event": { "enabled": false } - }, - "schedule": { - "type": "cron", - "expr": "0 9 * * 1-5", - "tz": "Asia/Shanghai", - "timeout": "30m" - }, - "identity": { - "role": "Sales Analyst", - "duties": ["Analyze sales data", "Generate weekly reports"], - "rules": ["Only access sales-related data"] - }, - "quota": { - "max": 2, - "queue": 10, - "priority": 5 - }, - "private_kb": { - "learn": { "on": true, "types": ["execution", "feedback", "insight"], "keep": 90 } - }, - "shared_kb": { - "refs": ["sales-policies", "product-catalog"] - }, - "resources": { - "p0": "__yao.inspiration", - "p1": "__yao.goal-gen", - "p2": "__yao.task-plan", - "p3": "__yao.validator", - "p4": "__yao.delivery", - "p5": "__yao.learning", - "agents": ["data-analyst", "chart-gen"], - "mcp": [{ "id": "database", "tools": ["query"] }] - }, - "delivery": { - "type": "email", - "opts": { "to": ["manager@company.com"] } - } - } -} - -// System automatically: -// 1. Creates private KB: agent_{team_id}_{agent_id}_kb -// 2. Registers with scheduler, allocates resources by quota -``` - -### Deleting AI Member - -```go -// Remove AI member via Team API -DELETE /api/teams/:team_id/members/:member_id - -// Manager will automatically stop this Agent on next Tick -``` - -## Execution State Persistence +### 8.3 Database Schema ```sql --- Execution history table CREATE TABLE autonomous_executions ( id VARCHAR(64) PRIMARY KEY, team_id VARCHAR(64) NOT NULL, @@ -1723,561 +667,63 @@ CREATE TABLE autonomous_executions ( goals JSON, tasks JSON, error TEXT, - delivery_result JSON, + result JSON, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, - INDEX idx_team_agent (team_id, agent_id), - INDEX idx_status (status), - INDEX idx_start_time (start_time) + INDEX idx_status (status) ); ``` -## Security Considerations +--- -1. **Team Isolation**: AI members can only access resources belonging to their team -2. **Permission Inheritance**: AI member permissions are determined by their role_id -3. **Resource Restrictions**: Callable resources limited via agent_config.resources -4. **Execution Timeout**: Prevent infinite execution via max_execution_time -5. **Audit Logs**: All execution records persisted to autonomous_executions table +## 9. Security -## External Input and Intervention Mechanism +1. **Team Isolation**: Agents only access their team's resources +2. **Permission Inheritance**: Permissions from role_id +3. **Resource Restrictions**: Limited by `resources` config +4. **Execution Timeout**: Enforced by `timeout` config +5. **Audit Logs**: All executions persisted -Besides scheduled triggers, Autonomous Agents need to respond to external inputs (human intervention, event notifications, etc.). +--- -### Input Types +## 10. Quick Reference -```go -// InputType input type -type InputType string - -const ( - InputTypeSchedule InputType = "schedule" // Scheduled trigger - InputTypeIntervene InputType = "intervene" // Human intervention (adjust goals/tasks) - InputTypeEvent InputType = "event" // External event (webhook, system event) - InputTypeCallback InputType = "callback" // Async task callback -) - -// ExternalInput external input -type ExternalInput struct { - ID string `json:"id"` - Type InputType `json:"type"` - Source string `json:"source"` // Source identifier - Priority int `json:"priority"` // Priority (1-10, 10 highest) - Content interface{} `json:"content"` // Input content - Metadata map[string]interface{} `json:"metadata"` - CreatedAt time.Time `json:"created_at"` -} -``` - -### Input Queue and Isolation - -Each Agent maintains an independent input queue for input isolation: - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Autonomous Agent โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Input Queue (Isolated) โ”‚ โ”‚ -โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ Schedule โ”‚ โ”‚ Intervene โ”‚ โ”‚ Event โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ Queue โ”‚ โ”‚ Queue โ”‚ โ”‚ Queue โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚(Scheduled)โ”‚ โ”‚(Intervention)โ”‚(Events) โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ–ผ โ”‚ โ”‚ -โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ Input Router โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ (Priority Sort) โ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ”‚ โ–ผ โ”‚ -โ”‚ Execution Engine โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -### Input Processing Strategy - -```go -// InputConfig input configuration (in AgentConfig) -type InputConfig struct { - // Input isolation settings - Isolation *IsolationConfig `json:"isolation"` - - // Processing strategy for each input type - Strategies map[InputType]*InputStrategy `json:"strategies"` -} - -// IsolationConfig isolation configuration -type IsolationConfig struct { - QueueSize int `json:"queue_size"` // Queue size limit - EnableRateLimit bool `json:"enable_rate_limit"` // Enable rate limiting - RatePerMinute int `json:"rate_per_minute"` // Max inputs per minute -} - -// InputStrategy input processing strategy -type InputStrategy struct { - Enabled bool `json:"enabled"` // Enable this input type - Priority int `json:"priority"` // Default priority - Action string `json:"action"` // immediate | queue | merge - // immediate: Process immediately, can interrupt current execution - // queue: Queue up, process by priority - // merge: Merge into current/next execution plan -} -``` - -### Intervention Processing Flow - -When receiving human intervention input: - -``` -External Intervention Input - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Intervene Handler โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ 1. Parse intervention intent โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข adjust_goal: Adjust current goal โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข add_task: Add new task โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข cancel_task: Cancel task โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข pause: Pause execution โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข resume: Resume execution โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข abort: Abort current execution โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Decide handling based on intervention type and current state โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ If currently executing: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข High priority intervention โ†’ Interrupt current task,โ”‚ โ”‚ -โ”‚ โ”‚ process immediately โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Low priority intervention โ†’ Schedule into current โ”‚ โ”‚ -โ”‚ โ”‚ task list โ”‚ โ”‚ -โ”‚ โ”‚ If currently idle: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Trigger new execution cycle โ”‚ โ”‚ -โ”‚ โ”‚ If intervention is plan-type: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Write to plan queue for later โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -### Intervention Type Definitions - -```go -// InterveneAction intervention action -type InterveneAction string - -const ( - InterveneAdjustGoal InterveneAction = "adjust_goal" // Adjust goal - InterveneAddTask InterveneAction = "add_task" // Add task - InterveneCancelTask InterveneAction = "cancel_task" // Cancel task - IntervenePause InterveneAction = "pause" // Pause - InterveneResume InterveneAction = "resume" // Resume - InterveneAbort InterveneAction = "abort" // Abort - IntervenePlan InterveneAction = "plan" // Queue for later plan -) - -// InterveneInput intervention input content -type InterveneInput struct { - Action InterveneAction `json:"action"` - TargetID string `json:"target_id,omitempty"` // Goal/task ID - Description string `json:"description"` // Intervention description - Data map[string]interface{} `json:"data,omitempty"` // Additional data - ScheduleAt *time.Time `json:"schedule_at,omitempty"` // Scheduled execution time -} -``` - -## Event Trigger Mechanism - -Besides scheduled triggers, supports multiple event sources to trigger Agent execution. - -### Event Sources - -```go -// EventSource event source configuration -type EventSource struct { - Type string `json:"type"` // webhook | database | mq | system - Config map[string]interface{} `json:"config"` - Filter *EventFilter `json:"filter"` // Event filter conditions - Mapping *EventMapping `json:"mapping"` // Event to input mapping -} - -// EventFilter event filter -type EventFilter struct { - EventTypes []string `json:"event_types"` // Subscribed event types - Conditions map[string]interface{} `json:"conditions"` // Filter conditions -} -``` - -### Configuration Example +### Trigger Config ```yaml -agent_config: - # ... other config ... - - # Input configuration - input: - isolation: - queue_size: 100 - enable_rate_limit: true - rate_per_minute: 10 - - strategies: - schedule: - enabled: true - priority: 5 - action: "immediate" - - intervene: - enabled: true - priority: 10 # Highest priority - action: "immediate" - - event: - enabled: true - priority: 7 - action: "queue" - - # Event source configuration - event_sources: - - type: "webhook" - config: - endpoint: "/webhook/agent/{agent_id}" - filter: - event_types: ["order.created", "customer.feedback"] - - - type: "database" - config: - table: "sales_orders" - trigger: "insert" - filter: - conditions: - amount: { "$gt": 10000 } +triggers: + schedule: { enabled: true } + intervene: { enabled: true, actions: [...] } + event: { enabled: false } ``` -## Plan Queue - -Supports queuing tasks for later plans, enabling delayed execution and batch processing. - -### Plan Queue Structure - -```go -// PlanQueue plan queue -type PlanQueue struct { - AgentID string `json:"agent_id"` - Items []PlanItem `json:"items"` -} - -// PlanItem plan item -type PlanItem struct { - ID string `json:"id"` - Type string `json:"type"` // goal | task | input - Content interface{} `json:"content"` - Priority int `json:"priority"` - ScheduleAt *time.Time `json:"schedule_at"` // nil means process on next execution - Source string `json:"source"` // Source (intervene, event) - CreatedAt time.Time `json:"created_at"` - Status string `json:"status"` // pending | processed | cancelled -} -``` - -### Plan Processing - -Before Phase 1 (Goal Generation), check the plan queue: - -``` -Execution Start - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Phase 0: Plan Processing โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ 1. Check due items in plan queue โ”‚ โ”‚ -โ”‚ โ”‚ 2. Sort by priority โ”‚ โ”‚ -โ”‚ โ”‚ 3. Merge into current execution: โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข goal type โ†’ Inject into goal generation โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข task type โ†’ Add directly to task list โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข input type โ†’ Process as additional input โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -Phase 1: Goal Generation - โ”‚ - ... -``` - -## Integration with Job System (Activity Monitor) - -Autonomous Agent task execution is based on the existing Job framework (`yao/job`), reusing its complete task scheduling, execution monitoring, and logging capabilities, with visual management through the **Activity Monitor** UI. - -### Job System Architecture - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Activity Monitor โ”‚ -โ”‚ (UI Dashboard) โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ โ€ข Task list and status โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Real-time progress tracking โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Execution log viewing โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Cancel/pause/retry operations โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Job Framework (yao/job) โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ โ€ข Job: Task definition (once/cron/daemon) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Execution: Execution instance (supports parent-child) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Worker: Executor (goroutine/process) โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Log: Multi-level execution logs โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Progress: Real-time progress tracking โ”‚ โ”‚ -โ”‚ โ”‚ โ€ข Health: Health check โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ”‚ - โ–ผ -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Autonomous Agent Executor โ”‚ -โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Phase 0 โ†’ Phase 1 โ†’ Phase 2 โ†’ Phase 3 โ†’ Phase 4 โ†’ Phase 5โ”‚ โ”‚ -โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -### Agent Execution Mapping to Job - -Each Autonomous Agent corresponds to a Job, each execution cycle corresponds to an Execution: - -```go -// Create Job corresponding to Agent -func createAgentJob(agent *AutonomousAgent) (*job.Job, error) { - jobData := map[string]interface{}{ - "name": fmt.Sprintf("Agent: %s", agent.AgentID), - "description": fmt.Sprintf("Autonomous Agent for team %s", agent.TeamID), - "category_id": "autonomous_agent", - "__yao_team_id": agent.TeamID, - } - - var j *job.Job - var err error - - switch agent.Config.Schedule.Type { - case "cron": - j, err = job.CronAndSave(job.GOROUTINE, jobData, agent.Config.Schedule.Expression) - case "daemon": - j, err = job.DaemonAndSave(job.GOROUTINE, jobData) - default: - j, err = job.OnceAndSave(job.GOROUTINE, jobData) - } - - if err != nil { - return nil, err - } - - // Associate Agent configuration - j.SetConfig(map[string]interface{}{ - "agent_id": agent.AgentID, - "team_id": agent.TeamID, - "agent_config": agent.Config, - }) - - return j, nil -} -``` - -### Execution and Execution Phases - -Each Execution runs the complete Agent cycle, tracking each phase via Progress and Log: - -```go -// Agent execution function (registered to Job) -func agentExecutionHandler(ctx *job.ExecutionContext) error { - execution := ctx.Execution - agentConfig := ctx.Args["agent_config"].(*AgentConfig) - - // Phase 0: Plan Processing - execution.Info("Phase 0: Processing plan queue") - execution.SetProgress(5, "Processing pending plans...") - processPlanQueue(ctx, agentConfig) - - // Phase 1: Goal Generation - execution.Info("Phase 1: Generating goals") - execution.SetProgress(15, "Generating goals...") - goals, err := generateGoals(ctx, agentConfig) - if err != nil { - execution.Error("Goal generation failed: %v", err) - return err - } - - // Phase 2: Task Decomposition - execution.Info("Phase 2: Decomposing tasks") - execution.SetProgress(30, "Decomposing tasks...") - tasks, err := decomposeTasks(ctx, agentConfig, goals) - if err != nil { - execution.Error("Task decomposition failed: %v", err) - return err - } - - // Phase 3: Task Execution (create child Execution for each task) - execution.Info("Phase 3: Executing %d tasks", len(tasks)) - for i, task := range tasks { - progress := 30 + (50 * (i + 1) / len(tasks)) - execution.SetProgress(progress, fmt.Sprintf("Task %d/%d: %s", i+1, len(tasks), task.Description)) - executeTaskWithChildExecution(ctx, execution, agentConfig, &task) - } - - // Phase 4: Delivery - execution.Info("Phase 4: Delivering results") - execution.SetProgress(85, "Generating deliverables...") - deliver(ctx, agentConfig, tasks) - - // Phase 5: Learning - execution.Info("Phase 5: Learning from execution") - execution.SetProgress(95, "Updating knowledge base...") - learn(ctx, agentConfig, goals, tasks) - - execution.SetProgress(100, "Completed") - return nil -} -``` - -### Child Task Tracking (Parent-Child Execution) - -Each task in Agent execution creates a child Execution, expandable in the Activity Monitor: - -```go -// Create child Execution for Agent task -func executeTaskWithChildExecution(ctx *job.ExecutionContext, parent *job.Execution, config *AgentConfig, task *Task) error { - // Create child Execution - childExec := &job.Execution{ - JobID: parent.JobID, - ParentExecutionID: &parent.ExecutionID, - Status: "running", - TriggerCategory: "agent_task", - ExecutionConfig: &job.ExecutionConfig{ - Type: job.ExecutionTypeFunc, - FuncID: fmt.Sprintf("task_%s", task.ID), - FuncName: task.Description, - }, - } - job.SaveExecution(childExec) - - // Execute task - childExec.Info("Starting task: %s", task.Description) - err := executeTask(ctx, config, task) - - // Update child Execution status - if err != nil { - childExec.Status = "failed" - childExec.Error("Task failed: %v", err) - } else { - childExec.Status = "completed" - childExec.Info("Task completed successfully") - } - job.SaveExecution(childExec) - - return err -} -``` - -### Activity Monitor Features - -Via Job API (`yao/openapi/job`), the Activity Monitor provides: - -| Feature | API | Description | -| ------------------ | ------------------------------------------------ | -------------------------- | -| Agent task list | `GET /api/jobs?category_id=autonomous_agent` | View all Agent Jobs | -| Execution history | `GET /api/jobs/:job_id/executions` | View execution history | -| Real-time progress | `GET /api/jobs/:job_id/executions/:id` | View current progress | -| Execution logs | `GET /api/jobs/:job_id/executions/:id/logs` | View detailed logs | -| Expand child tasks | `GET /api/jobs/:job_id/executions?parent_id=:id` | View child tasks | -| Cancel execution | `POST /api/jobs/:job_id/stop` | Cancel running task | -| Manual trigger | `POST /api/jobs/:job_id/trigger` | Manually trigger execution | - -### Log Levels - -Agent execution logs map to Job log levels: - -```go -// Log level mapping -execution.Debug("Detailed debug info") // Debug -execution.Info("Phase start/complete") // Info -execution.Warn("Non-fatal warning") // Warn -execution.Error("Error, interrupt execution") // Error -``` - -### Job Configuration +### Phase Agents ```yaml -agent_config: - # ... other config ... - - # Job execution configuration - job: - mode: "goroutine" # goroutine | process - max_worker_nums: 1 # Max concurrent executions - max_retry_count: 3 # Max retry count - default_timeout: 1800 # Default timeout (seconds) - priority: 5 # Execution priority (affects queue sorting) +resources: + p0: "__yao.inspiration" # Inspiration + p1: "__yao.goal-gen" # Goal Generator + p2: "__yao.task-plan" # Task Planner + p3: "__yao.validator" # Validator + p4: "__yao.delivery" # Delivery + p5: "__yao.learning" # Learning ``` -## Complete Config Structure +### Quota -```go -// Config AI member complete configuration -type Config struct { - Triggers *Triggers `json:"triggers,omitempty"` // Trigger sources (all enabled by default) - Schedule *Schedule `json:"schedule,omitempty"` // Timing config - Identity *Identity `json:"identity"` // Role & duties - Quota *Quota `json:"quota"` // Concurrency quota - PrivateKB *KB `json:"private_kb"` // Private KB - SharedKB *KB `json:"shared_kb,omitempty"` // Shared KB refs - Resources *Resources `json:"resources"` // Agents & tools - Delivery *Delivery `json:"delivery"` // Output config - Input *Input `json:"input,omitempty"` // Input isolation - Events []Event `json:"events,omitempty"` // Event sources - Monitor *Monitor `json:"monitor,omitempty"` // Monitoring -} - -// Triggers trigger sources (all enabled by default) -type Triggers struct { - Schedule *Trigger `json:"schedule,omitempty"` - Intervene *Trigger `json:"intervene,omitempty"` - Event *Trigger `json:"event,omitempty"` -} - -// Trigger single trigger config -type Trigger struct { - Enabled bool `json:"enabled"` - Actions []string `json:"actions,omitempty"` // For intervene only -} - -// Monitor monitoring config -type Monitor struct { - On bool `json:"on"` - Alerts []Alert `json:"alerts,omitempty"` -} - -// Alert rule definition -type Alert struct { - Name string `json:"name"` // Rule name - When string `json:"when"` // failed | timeout | error_rate - Value float64 `json:"value"` // Threshold - Window string `json:"window"` // 1h | 24h - Do []Action `json:"do"` // Actions - Cooldown string `json:"cooldown"` // Cooldown period -} - -// Action alert action -type Action struct { - Type string `json:"type"` // email | webhook | notify - Opts map[string]interface{} `json:"opts"` -} +```yaml +quota: + max: 2 # Max concurrent + queue: 10 # Queue size + priority: 5 # 1-10 +``` + +### Schedule + +```yaml +schedule: + type: cron # cron | interval + expr: "0 9 * * 1-5" # Cron or duration + tz: Asia/Shanghai + timeout: 30m ``` From 46d815affcf409907f6c2f031bb4dfac77769a51 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 08:58:19 +0800 Subject: [PATCH 04/12] Refactor Autonomous Agent Design Document for Improved Clarity and Structure - Revised the document to enhance clarity by updating section titles and terminology, such as changing "Overview" to "What is it?" and "Key Characteristics" to "Key points." - Streamlined the architecture section, renaming components for consistency and clarity, including changes to trigger sources and agent management terminology. - Updated execution flow diagrams and descriptions to reflect the new structure, improving understanding of the agent's operational phases. - Enhanced the configuration section to provide a clearer overview of triggers, scheduling, and resource management, ensuring better organization throughout the document. --- agent/autonomous/DESIGN.md | 498 ++++++++++++++++++------------------- 1 file changed, 245 insertions(+), 253 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index c41d61eb..50b97299 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -1,39 +1,39 @@ -# Autonomous Agent Design Document +# Autonomous Agent -## 1. Overview +## 1. What is it? -An **Autonomous Agent** is an AI team member that operates independently, makes decisions, and executes tasks proactively. Unlike Assistants that respond to user requests, Autonomous Agents run periodically based on job responsibilities. +An **Autonomous Agent** is an AI team member. It works on its own, makes decisions, and runs tasks without waiting for user input. -**Key Characteristics:** +**Key points:** -- **Team Member**: Managed like human members, belongs to a Team -- **Job Responsibilities**: Has defined duties (e.g., "Sales Manager tracks KPIs") -- **Dynamic Lifecycle**: Created/destroyed via Team API -- **Multi-Trigger**: Activated by schedule, human intervention, or events -- **Self-Learning**: Maintains private knowledge base, learns from execution +- Belongs to a Team, managed like human members +- Has clear job duties (e.g., "Sales Manager: track KPIs, make reports") +- Created and deleted via Team API +- Runs on schedule, or when triggered by humans or events +- Learns from each run, stores knowledge in private KB --- ## 2. Architecture -### 2.1 System Overview +### 2.1 System Flow ```mermaid flowchart TB - subgraph Triggers["Trigger Sources"] - WC[/"โฐ World Clock
(Schedule)"/] - HI[/"๐Ÿ‘ค Human
(Intervene)"/] - EV[/"๐Ÿ“ก Events
(Webhook/DB)"/] + subgraph Triggers["Triggers"] + WC[/"โฐ Schedule"/] + HI[/"๐Ÿ‘ค Human"/] + EV[/"๐Ÿ“ก Event"/] end - subgraph Manager["Agent Manager"] - TC{"Trigger
Enabled?"} - Cache[("Agent Cache")] - Dedup{"Dedup
Check"} - Queue["Priority Queue"] + subgraph Manager["Manager"] + TC{"Enabled?"} + Cache[("Cache")] + Dedup{"Dedup?"} + Queue["Queue"] end - subgraph Pool["Worker Pool"] + subgraph Pool["Workers"] W1["Worker"] W2["Worker"] W3["Worker"] @@ -43,33 +43,33 @@ flowchart TB P0["P0: Inspiration"] P1["P1: Goals"] P2["P2: Tasks"] - P3["P3: Execute"] + P3["P3: Run"] P4["P4: Deliver"] P5["P5: Learn"] end subgraph Storage["Storage"] - KB[("Private KB")] - DB[("Executions")] - Job[("Job System")] + KB[("KB")] + DB[("DB")] + Job[("Job")] end WC & HI & EV --> TC TC -->|Yes| Cache - TC -->|No| X[/Ignored/] + TC -->|No| X[/Skip/] Cache --> Dedup - Dedup -->|Pass| Queue - Dedup -->|Skip| Cache + Dedup -->|OK| Queue + Dedup -->|Dup| Cache Queue --> W1 & W2 & W3 W1 & W2 & W3 --> P0 P0 --> P1 --> P2 --> P3 --> P4 --> P5 P5 --> KB & DB & Job - KB -.->|Experience| P0 + KB -.->|History| P0 ``` -### 2.2 Team Integration +### 2.2 Team Structure -AI members are stored in `team_members` table with `member_type = "ai"`: +AI members live in `team_members` table with `member_type = "ai"`: ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” @@ -78,7 +78,6 @@ AI members are stored in `team_members` table with `member_type = "ai"`: โ”‚ โ”‚ AI Members โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚Sales Managerโ”‚ โ”‚Data Analyst โ”‚ โ”‚CS Specialistโ”‚ โ”‚ โ”‚ -โ”‚ โ”‚ โ”‚ Duties: โ”‚ โ”‚ Duties: โ”‚ โ”‚ Duties: โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Track KPIsโ”‚ โ”‚ โ€ข Analyze โ”‚ โ”‚ โ€ข Tickets โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Reports โ”‚ โ”‚ โ€ข Reports โ”‚ โ”‚ โ€ข Inquiries โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ @@ -96,9 +95,9 @@ AI members are stored in `team_members` table with `member_type = "ai"`: CREATE TABLE team_members ( id BIGINT PRIMARY KEY AUTO_INCREMENT, team_id VARCHAR(64) NOT NULL, - user_id VARCHAR(64), -- Human members + user_id VARCHAR(64), -- for humans member_type VARCHAR(32) NOT NULL, -- "user" | "ai" - agent_id VARCHAR(64), -- AI members only + agent_id VARCHAR(64), -- for AI only agent_config JSON, -- AI config status VARCHAR(32) DEFAULT 'active', INDEX idx_team_id (team_id), @@ -110,7 +109,7 @@ CREATE TABLE team_members ( ## 3. How It Works -### 3.1 Trigger โ†’ Schedule โ†’ Execute +### 3.1 Flow: Trigger โ†’ Schedule โ†’ Run ```mermaid sequenceDiagram @@ -120,39 +119,39 @@ sequenceDiagram participant S as Scheduler participant W as Worker participant E as Executor - participant A as Agents (P0-P5) - participant KB as Private KB + participant A as Phase Agents + participant KB as KB - T->>M: Trigger Event - M->>M: Check trigger enabled - M->>M: Get agent from cache - M->>M: Dedup check - M->>S: Submit request + T->>M: Event + M->>M: Check enabled + M->>M: Get from cache + M->>M: Check dedup + M->>S: Submit S->>S: Check quota - S->>S: Priority sort + S->>S: Sort by priority S->>W: Dispatch - W->>E: Execute + W->>E: Run - loop Phase 0-5 - E->>A: Call phase agent + loop P0 to P5 + E->>A: Call agent A-->>E: Result end - E->>KB: Store learning - E-->>W: Complete + E->>KB: Save learning + E-->>W: Done ``` -### 3.2 Trigger Sources +### 3.2 Triggers -| Trigger | Description | Config | -| ------------- | --------------------------- | -------------------- | -| **Schedule** | World Clock (cron/interval) | `triggers.schedule` | -| **Intervene** | Human intervention | `triggers.intervene` | -| **Event** | Webhook, DB changes | `triggers.event` | +| Type | What | Config | +| ------------ | ------------------------ | -------------------- | +| **Schedule** | Timer (cron or interval) | `triggers.schedule` | +| **Human** | Manual action | `triggers.intervene` | +| **Event** | Webhook, DB change | `triggers.event` | -All triggers enabled by default. Configure per-agent: +All on by default. Turn off per agent: ```yaml triggers: @@ -161,114 +160,113 @@ triggers: event: { enabled: false } ``` -### 3.3 Concurrency Control +### 3.3 Concurrency -Two-level control prevents resource monopolization: +Two levels to prevent one agent from using all resources: ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Global Worker Pool (10 workers) โ”‚ +โ”‚ Global Pool (10 workers) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ–ผ โ–ผ โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Sales Manager โ”‚ โ”‚ Data Analyst โ”‚ โ”‚ CS Specialist โ”‚ -โ”‚ Quota: 3 โ”‚ โ”‚ Quota: 2 โ”‚ โ”‚ Quota: 3 โ”‚ -โ”‚ Current: 2 โœ“ โ”‚ โ”‚ Current: 2 (full)โ”‚ โ”‚ Current: 1 โœ“ โ”‚ +โ”‚ Limit: 3 โ”‚ โ”‚ Limit: 2 โ”‚ โ”‚ Limit: 3 โ”‚ +โ”‚ Now: 2 โœ“ โ”‚ โ”‚ Now: 2 (full) โ”‚ โ”‚ Now: 1 โœ“ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` -### 3.4 Deduplication +### 3.4 Dedup -**Execution-level** (fast, memory): +**Fast check** (in memory): ```go -key := fmt.Sprintf("%s:%s:%s", agentID, triggerType, window) -if cache.Has(key) { skip } +key := agentID + ":" + triggerType + ":" + window +if has(key) { skip } ``` -**Semantic-level** (Agent-based, for goals/tasks): +**Smart check** (for goals/tasks): -- Dedup Agent analyzes historical records +- Dedup Agent looks at history - Returns: `skip` | `merge` | `proceed` -### 3.5 Agent Cache +### 3.5 Cache -Avoids frequent DB queries: +Keeps agents in memory. No DB query on each tick: ```go type AgentCache struct { - agents map[string]*Agent // agent_id -> agent - byTeam map[string][]string // team_id -> []agent_id + agents map[string]*Agent // agent_id -> agent + byTeam map[string][]string // team_id -> agent_ids } - -// Refresh: startup, on change, periodic (hourly) +// Refresh: on start, on change, every hour ``` --- -## 4. Execution Phases +## 4. Phases -### 4.1 Phase Overview +### 4.1 Overview ``` -P0: Inspiration โ†’ P1: Goals โ†’ P2: Tasks โ†’ P3: Execute โ†’ P4: Deliver โ†’ P5: Learn +P0: Inspiration โ†’ P1: Goals โ†’ P2: Tasks โ†’ P3: Run โ†’ P4: Deliver โ†’ P5: Learn ``` -| Phase | Agent | Input | Output | -| ----- | -------------- | -------------------------------------- | ----------------- | -| P0 | Inspiration | Data changes, world news, time context | InspirationReport | -| P1 | Goal Generator | Inspiration + KB experience | Goals[] | -| P2 | Task Planner | Goals + available resources | Tasks[] | -| P3 | Validator | Task results | Validated results | -| P4 | Delivery | All results | Email/Report/File | -| P5 | Learning | Execution summary | KB entries | +| Phase | Agent | In | Out | +| ----- | ----------- | ---------------- | --------------- | +| P0 | Inspiration | Data, news, time | Report | +| P1 | Goal Gen | Report + history | Goals | +| P2 | Task Plan | Goals + tools | Tasks | +| P3 | Validator | Results | Checked results | +| P4 | Delivery | All results | Email/File | +| P5 | Learning | Summary | KB entries | -### 4.2 Phase 0: Inspiration +### 4.2 P0: Inspiration -Collects context to generate high-value goals: +Gathers info to help make good goals: ```go type InspirationReport struct { - Summary string // Overall situation - Highlights []Highlight // Key findings (data_change|event|deadline|world_news) - Opportunities []Opportunity // Discovered opportunities - Risks []Risk // Potential risks - WorldInsights []WorldInsight // External world insights - Suggestions []string // Focus areas + Summary string // What's happening + Highlights []Highlight // Key changes + Opportunities []Opportunity // Chances to act + Risks []Risk // Things to watch + WorldInsights []WorldInsight // News from outside + Suggestions []string // What to focus on } ``` -**Data sources:** +**Sources:** -- Internal: Data changes, events, feedback, pending items -- External: Web search (industry news, competitors) -- Time: Day of week, month end, deadlines +- Internal: Data changes, events, feedback, pending work +- External: Web search (news, competitors) +- Time: Day of week, deadlines -### 4.3 Phase 1: Goal Generation +### 4.3 P1: Goals -Uses inspiration report to generate goals: +Uses inspiration to make goals: ``` Prompt: -You are [Sales Manager], responsible for [tracking KPIs, generating reports]. +You are [Sales Manager]. Your job: [track KPIs, make reports]. -## Inspiration Report -### Key Findings -- [High] Data: 15 new sales records (+50%) -- [High] Deadline: Friday, prepare weekly report -- [High] External: Competitor launched new product +## Report +### Key Items +- [High] Data: 15 new sales (+50%) +- [High] Deadline: Friday report due +- [High] News: Competitor launched product -### Opportunities -- Sales exceeded last week by 20% -- Industry report shows market growth +### Chances +- Sales up 20% vs last week +- Market growing -Please generate today's most valuable work goals. +Make today's goals. ``` -### 4.4 Phase 2: Task Decomposition +### 4.4 P2: Tasks -Breaks goals into executable tasks: +Breaks goals into steps: ```go type Task struct { @@ -276,22 +274,22 @@ type Task struct { GoalID string Description string ExecutorType string // "assistant" | "mcp" - ExecutorID string // Assistant ID or MCP tool + ExecutorID string } ``` -### 4.5 Phase 3: Execution +### 4.5 P3: Run For each task: -1. Call specified Assistant or MCP Tool -2. Collect result -3. Call Validator to verify +1. Call Assistant or MCP Tool +2. Get result +3. Validate 4. Update status -### 4.6 Phase 4: Delivery +### 4.6 P4: Deliver -Generates deliverables based on config: +Send output: ```yaml delivery: @@ -300,42 +298,42 @@ delivery: to: ["manager@company.com"] ``` -### 4.7 Phase 5: Learning +### 4.7 P5: Learn -Analyzes execution, writes to private KB: +Save to KB: -| Category | Examples | -| ----------- | ----------------------------------- | -| `execution` | Task process, success/failure cases | -| `feedback` | Validation results, error analysis | -| `insight` | Patterns, optimization suggestions | +| Type | Examples | +| ----------- | ------------------------ | +| `execution` | What worked, what failed | +| `feedback` | Errors, fixes | +| `insight` | Patterns, tips | --- -## 5. Configuration +## 5. Config -### 5.1 Config Structure +### 5.1 Structure ```go type Config struct { - Triggers *Triggers `json:"triggers,omitempty"` // Trigger sources - Schedule *Schedule `json:"schedule,omitempty"` // Timing - Identity *Identity `json:"identity"` // Role & duties - Quota *Quota `json:"quota"` // Concurrency - PrivateKB *KB `json:"private_kb"` // Private KB - SharedKB *KB `json:"shared_kb,omitempty"` // Shared KB refs - Resources *Resources `json:"resources"` // Agents & tools - Delivery *Delivery `json:"delivery"` // Output - Input *Input `json:"input,omitempty"` // Input isolation - Events []Event `json:"events,omitempty"` // Event sources - Monitor *Monitor `json:"monitor,omitempty"` // Monitoring + Triggers *Triggers `json:"triggers,omitempty"` + Schedule *Schedule `json:"schedule,omitempty"` + Identity *Identity `json:"identity"` + Quota *Quota `json:"quota"` + PrivateKB *KB `json:"private_kb"` + SharedKB *KB `json:"shared_kb,omitempty"` + Resources *Resources `json:"resources"` + Delivery *Delivery `json:"delivery"` + Input *Input `json:"input,omitempty"` + Events []Event `json:"events,omitempty"` + Monitor *Monitor `json:"monitor,omitempty"` } ``` -### 5.2 Type Definitions +### 5.2 Types ```go -// Triggers (all enabled by default) +// Triggers - all on by default type Triggers struct { Schedule *Trigger `json:"schedule,omitempty"` Intervene *Trigger `json:"intervene,omitempty"` @@ -344,54 +342,54 @@ type Triggers struct { type Trigger struct { Enabled bool `json:"enabled"` - Actions []string `json:"actions,omitempty"` // For intervene only + Actions []string `json:"actions,omitempty"` // for intervene } // Schedule type Schedule struct { Type string `json:"type"` // cron | interval Expr string `json:"expr"` // "0 9 * * 1-5" or "1h" - TZ string `json:"tz"` // Timezone - Timeout string `json:"timeout"` // Max execution time + TZ string `json:"tz"` + Timeout string `json:"timeout"` } // Identity type Identity struct { - Role string `json:"role"` // Role name - Duties []string `json:"duties"` // Responsibilities - Rules []string `json:"rules"` // Constraints + Role string `json:"role"` + Duties []string `json:"duties"` + Rules []string `json:"rules"` } // Quota type Quota struct { - Max int `json:"max"` // Max concurrent (default: 2) - Queue int `json:"queue"` // Queue size (default: 10) + Max int `json:"max"` // max running (default: 2) + Queue int `json:"queue"` // queue size (default: 10) Priority int `json:"priority"` // 1-10 (default: 5) } // KB type KB struct { - ID string `json:"id,omitempty"` // Collection ID - Refs []string `json:"refs,omitempty"` // Shared refs - Learn *Learn `json:"learn,omitempty"` // Learning config + ID string `json:"id,omitempty"` + Refs []string `json:"refs,omitempty"` + Learn *Learn `json:"learn,omitempty"` } type Learn struct { - On bool `json:"on"` // Enable - Types []string `json:"types"` // ["execution", "feedback", "insight"] - Keep int `json:"keep"` // Retention days, 0 = forever + On bool `json:"on"` + Types []string `json:"types"` // execution, feedback, insight + Keep int `json:"keep"` // days, 0 = forever } // Resources type Resources struct { - P0 string `json:"p0"` // Inspiration - P1 string `json:"p1"` // Goal Generator - P2 string `json:"p2"` // Task Planner - P3 string `json:"p3"` // Validator - P4 string `json:"p4"` // Delivery - P5 string `json:"p5"` // Learning - Agents []string `json:"agents"` // Callable assistants - MCP []MCP `json:"mcp"` // MCP services + P0 string `json:"p0"` // Inspiration + P1 string `json:"p1"` // Goal Gen + P2 string `json:"p2"` // Task Plan + P3 string `json:"p3"` // Validator + P4 string `json:"p4"` // Delivery + P5 string `json:"p5"` // Learning + Agents []string `json:"agents"` + MCP []MCP `json:"mcp"` } type MCP struct { @@ -413,9 +411,9 @@ type Monitor struct { type Alert struct { Name string `json:"name"` - When string `json:"when"` // failed | timeout | error_rate - Value float64 `json:"value"` // Threshold - Window string `json:"window"` // 1h | 24h + When string `json:"when"` // failed | timeout | error_rate + Value float64 `json:"value"` + Window string `json:"window"` // 1h | 24h Do []Action `json:"do"` Cooldown string `json:"cooldown"` } @@ -426,7 +424,7 @@ type Action struct { } ``` -### 5.3 Full Example +### 5.3 Example ```json { @@ -446,8 +444,8 @@ type Action struct { }, "identity": { "role": "Sales Analyst", - "duties": ["Analyze sales data", "Generate weekly reports"], - "rules": ["Only access sales-related data"] + "duties": ["Analyze sales", "Make weekly reports"], + "rules": ["Only access sales data"] }, "quota": { "max": 2, "queue": 10, "priority": 5 }, "private_kb": { @@ -457,7 +455,7 @@ type Action struct { "keep": 90 } }, - "shared_kb": { "refs": ["sales-policies", "product-catalog"] }, + "shared_kb": { "refs": ["sales-policies", "products"] }, "resources": { "p0": "__yao.inspiration", "p1": "__yao.goal-gen", @@ -480,13 +478,11 @@ type Action struct { ## 6. Lifecycle -### 6.1 State Diagram +### 6.1 States ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” POST create โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚ โ”‚ -โ”‚ None โ”‚ โ”‚ Active โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ +โ”‚ None โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚ Active โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ” โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ PATCH pause โ”‚ PATCH resume @@ -502,27 +498,25 @@ type Action struct { โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` -### 6.2 State Transitions +### 6.2 Transitions -| From | To | Trigger | -| ------------- | ------- | --------------------- | -| - | active | POST create member | -| active | paused | PATCH status="paused" | -| paused | active | PATCH status="active" | -| active/paused | deleted | DELETE member | +| From | To | How | +| ------ | ------- | --------------------- | +| - | active | POST create | +| active | paused | PATCH status="paused" | +| paused | active | PATCH status="active" | +| any | deleted | DELETE | -### 6.3 Initialization +### 6.3 On Create -On create: +1. Check config +2. Make agent_id if missing +3. Create KB: `agent_{team_id}_{agent_id}_kb` +4. Add to cache +5. Create Job +6. Set active -1. Validate config -2. Generate agent_id (if not provided) -3. Create private KB: `agent_{team_id}_{agent_id}_kb` -4. Register with Manager (add to cache) -5. Create Job entry -6. Set status = "active" - -### 6.4 Active State +### 6.4 Running ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” @@ -533,31 +527,29 @@ On create: โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` -### 6.5 Termination +### 6.5 On Delete -On delete: - -1. Cancel running executions +1. Stop running jobs 2. Remove from cache -3. Delete Job entry -4. Handle KB (delete or archive) +3. Delete Job +4. Delete or archive KB 5. Soft delete record --- ## 7. Integrations -### 7.1 Job System (Activity Monitor) +### 7.1 Job System -Each Agent maps to a Job, each execution to an Execution: +Each agent = 1 Job. Each run = 1 Execution. ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Activity Monitor (UI) โ”‚ -โ”‚ โ€ข Task list and status โ”‚ -โ”‚ โ€ข Real-time progress โ”‚ -โ”‚ โ€ข Execution logs โ”‚ -โ”‚ โ€ข Cancel/pause/retry โ”‚ +โ”‚ โ€ข List jobs โ”‚ +โ”‚ โ€ข See progress โ”‚ +โ”‚ โ€ข View logs โ”‚ +โ”‚ โ€ข Cancel/retry โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ–ผ @@ -569,59 +561,59 @@ Each Agent maps to a Job, each execution to an Execution: **APIs:** -| Feature | API | -| ----------- | -------------------------------------------- | -| List agents | `GET /api/jobs?category_id=autonomous_agent` | -| History | `GET /api/jobs/:job_id/executions` | -| Progress | `GET /api/jobs/:job_id/executions/:id` | -| Logs | `GET /api/jobs/:job_id/executions/:id/logs` | -| Cancel | `POST /api/jobs/:job_id/stop` | -| Trigger | `POST /api/jobs/:job_id/trigger` | +| Action | API | +| -------- | -------------------------------------------- | +| List | `GET /api/jobs?category_id=autonomous_agent` | +| History | `GET /api/jobs/:job_id/executions` | +| Progress | `GET /api/jobs/:job_id/executions/:id` | +| Logs | `GET /api/jobs/:job_id/executions/:id/logs` | +| Cancel | `POST /api/jobs/:job_id/stop` | +| Trigger | `POST /api/jobs/:job_id/trigger` | -### 7.2 Private Knowledge Base +### 7.2 Private KB -Auto-created per agent: `agent_{team_id}_{agent_id}_kb` +Made on agent create: `agent_{team_id}_{agent_id}_kb` -**Learning categories:** +**What it stores:** -- `execution`: Task process, success/failure -- `feedback`: Validation, errors -- `insight`: Patterns, best practices +- `execution`: What worked, what failed +- `feedback`: Errors, fixes +- `insight`: Patterns, tips -**Lifecycle:** +**When:** -- Create: On agent creation -- Update: After each execution (P5) -- Cleanup: Based on `keep` config -- Delete: On agent deletion (or archive) +- Create: On agent create +- Update: After P5 +- Clean: Based on `keep` days +- Delete: On agent delete ### 7.3 External Input -**Input types:** +**Types:** -- `schedule`: World Clock -- `intervene`: Human intervention -- `event`: Webhooks, DB triggers -- `callback`: Async task callbacks +- `schedule`: Timer +- `intervene`: Human action +- `event`: Webhook, DB change +- `callback`: Async result -**Intervention actions:** +**Human actions:** -- `adjust_goal`: Modify current goal -- `add_task`: Add new task -- `cancel_task`: Cancel task +- `adjust_goal`: Change goal +- `add_task`: Add task +- `cancel_task`: Stop task - `pause` / `resume` / `abort` -- `plan`: Queue for later +- `plan`: Do later **Plan Queue:** -- Stores deferred goals/tasks -- Processed at start of next execution +- Holds tasks for later +- Runs at next cycle start --- -## 8. API Reference +## 8. API -### 8.1 Core Interfaces +### 8.1 Manager ```go type Manager interface { @@ -635,7 +627,7 @@ type Manager interface { } ``` -### 8.2 Execution State +### 8.2 State ```go type State struct { @@ -644,8 +636,8 @@ type State struct { AgentID string StartTime time.Time EndTime *time.Time - Status Status // pending | running | completed | failed - Phase Phase // inspiration | goal_generation | task_decomposition | task_execution | delivery | learning + Status Status // pending | running | completed | failed + Phase Phase // inspiration | goal_gen | task_plan | run | deliver | learn Goals []Goal Tasks []Task Error string @@ -653,7 +645,7 @@ type State struct { } ``` -### 8.3 Database Schema +### 8.3 Database ```sql CREATE TABLE autonomous_executions ( @@ -678,17 +670,17 @@ CREATE TABLE autonomous_executions ( ## 9. Security -1. **Team Isolation**: Agents only access their team's resources -2. **Permission Inheritance**: Permissions from role_id -3. **Resource Restrictions**: Limited by `resources` config -4. **Execution Timeout**: Enforced by `timeout` config -5. **Audit Logs**: All executions persisted +1. **Team only**: Agent sees only its team's data +2. **Role rules**: Uses role_id permissions +3. **Limited tools**: Only what's in `resources` +4. **Timeout**: Stops if runs too long +5. **Logs**: All runs saved --- -## 10. Quick Reference +## 10. Quick Ref -### Trigger Config +### Triggers ```yaml triggers: @@ -701,20 +693,20 @@ triggers: ```yaml resources: - p0: "__yao.inspiration" # Inspiration - p1: "__yao.goal-gen" # Goal Generator - p2: "__yao.task-plan" # Task Planner - p3: "__yao.validator" # Validator - p4: "__yao.delivery" # Delivery - p5: "__yao.learning" # Learning + p0: "__yao.inspiration" + p1: "__yao.goal-gen" + p2: "__yao.task-plan" + p3: "__yao.validator" + p4: "__yao.delivery" + p5: "__yao.learning" ``` ### Quota ```yaml quota: - max: 2 # Max concurrent - queue: 10 # Queue size + max: 2 # max running + queue: 10 # queue size priority: 5 # 1-10 ``` @@ -722,8 +714,8 @@ quota: ```yaml schedule: - type: cron # cron | interval - expr: "0 9 * * 1-5" # Cron or duration + type: cron + expr: "0 9 * * 1-5" tz: Asia/Shanghai timeout: 30m ``` From a9c1eb9bf5fb3f7616a156a0129a6d6e0fa4d936 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 09:08:57 +0800 Subject: [PATCH 05/12] Update Autonomous Agent Design Document to Clarify Execution Flow and Trigger Handling - Revised the execution flow diagrams to clearly differentiate between schedule and human/event triggers, enhancing understanding of the agent's operational phases. - Updated the P0: Inspiration phase to specify it operates under a schedule-only context, while human/event triggers directly generate goals. - Improved the documentation for each phase, adding clarity on input and output expectations, particularly for the Inspiration phase. - Enhanced the overall structure of the document to better reflect the distinct paths of execution based on trigger types. --- agent/autonomous/DESIGN.md | 149 ++++++++++++++++++++++--------------- 1 file changed, 90 insertions(+), 59 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index 50b97299..eb81832d 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -40,7 +40,7 @@ flowchart TB end subgraph Executor["Executor"] - P0["P0: Inspiration"] + P0["P0: Inspiration
(Schedule only)"] P1["P1: Goals"] P2["P2: Tasks"] P3["P3: Run"] @@ -54,14 +54,16 @@ flowchart TB Job[("Job")] end - WC & HI & EV --> TC + WC --> TC + HI & EV --> TC TC -->|Yes| Cache TC -->|No| X[/Skip/] Cache --> Dedup Dedup -->|OK| Queue Dedup -->|Dup| Cache Queue --> W1 & W2 & W3 - W1 & W2 & W3 --> P0 + W1 --> P0 + W2 & W3 -.->|Human/Event| P1 P0 --> P1 --> P2 --> P3 --> P4 --> P5 P5 --> KB & DB & Job KB -.->|History| P0 @@ -134,7 +136,12 @@ sequenceDiagram W->>E: Run - loop P0 to P5 + alt Schedule trigger + E->>A: P0: Inspiration + A-->>E: Report + end + + loop P1 to P5 E->>A: Call agent A-->>E: Result end @@ -210,19 +217,22 @@ type AgentCache struct { ### 4.1 Overview ``` -P0: Inspiration โ†’ P1: Goals โ†’ P2: Tasks โ†’ P3: Run โ†’ P4: Deliver โ†’ P5: Learn +Schedule: P0 โ†’ P1 โ†’ P2 โ†’ P3 โ†’ P4 โ†’ P5 +Human/Event: P1 โ†’ P2 โ†’ P3 โ†’ P4 โ†’ P5 ``` -| Phase | Agent | In | Out | -| ----- | ----------- | ---------------- | --------------- | -| P0 | Inspiration | Data, news, time | Report | -| P1 | Goal Gen | Report + history | Goals | -| P2 | Task Plan | Goals + tools | Tasks | -| P3 | Validator | Results | Checked results | -| P4 | Delivery | All results | Email/File | -| P5 | Learning | Summary | KB entries | +| Phase | Agent | In | Out | When | +| ----- | ----------- | ---------------- | --------------- | ------------- | +| P0 | Inspiration | Data, news, time | Report | Schedule only | +| P1 | Goal Gen | Report + history | Goals | Always | +| P2 | Task Plan | Goals + tools | Tasks | Always | +| P3 | Validator | Results | Checked results | Always | +| P4 | Delivery | All results | Email/File | Always | +| P5 | Learning | Summary | KB entries | Always | -### 4.2 P0: Inspiration +### 4.2 P0: Inspiration (Schedule only) + +**Skipped for Human/Event triggers.** They already have clear intent. Gathers info to help make good goals: @@ -245,7 +255,9 @@ type InspirationReport struct { ### 4.3 P1: Goals -Uses inspiration to make goals: +**For Schedule:** Uses inspiration report to make goals. + +**For Human/Event:** Uses the input directly as goals (or to generate goals). ``` Prompt: @@ -382,10 +394,10 @@ type Learn struct { // Resources type Resources struct { - P0 string `json:"p0"` // Inspiration - P1 string `json:"p1"` // Goal Gen - P2 string `json:"p2"` // Task Plan - P3 string `json:"p3"` // Validator + P0 string `json:"p0"` // Inspiration (Schedule only) + P1 string `json:"p1"` // Goals + P2 string `json:"p2"` // Tasks + P3 string `json:"p3"` // Validation P4 string `json:"p4"` // Delivery P5 string `json:"p5"` // Learning Agents []string `json:"agents"` @@ -458,9 +470,9 @@ type Action struct { "shared_kb": { "refs": ["sales-policies", "products"] }, "resources": { "p0": "__yao.inspiration", - "p1": "__yao.goal-gen", - "p2": "__yao.task-plan", - "p3": "__yao.validator", + "p1": "__yao.goals", + "p2": "__yao.tasks", + "p3": "__yao.validation", "p4": "__yao.delivery", "p5": "__yao.learning", "agents": ["data-analyst", "chart-gen"], @@ -478,27 +490,16 @@ type Action struct { ## 6. Lifecycle -### 6.1 States +### 6.1 Agent States +```mermaid +stateDiagram-v2 + [*] --> Active: POST create + Active --> Paused: PATCH pause + Paused --> Active: PATCH resume + Active --> [*]: DELETE + Paused --> [*]: DELETE ``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” POST create โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ None โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ โ”‚ Active โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ” -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜ โ”‚ - โ”‚ โ”‚ - PATCH pause โ”‚ PATCH resume - โ–ผ โ”‚ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ - โ”‚ Paused โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ - โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜ - โ”‚ - DELETE โ”‚ - โ–ผ - โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” - โ”‚ Deleted โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -### 6.2 Transitions | From | To | How | | ------ | ------- | --------------------- | @@ -507,7 +508,7 @@ type Action struct { | paused | active | PATCH status="active" | | any | deleted | DELETE | -### 6.3 On Create +### 6.2 On Create 1. Check config 2. Make agent_id if missing @@ -516,18 +517,7 @@ type Action struct { 5. Create Job 6. Set active -### 6.4 Running - -``` -โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” -โ”‚ Idle โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Triggeredโ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Running โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚ Learning โ”‚ -โ”‚ โ”‚โ—€โ”€โ”€โ”€โ”€โ”‚ โ”‚ โ”‚ (P0-P4) โ”‚ โ”‚ (P5) โ”‚ -โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ - โ–ฒ โ”‚ - โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ -``` - -### 6.5 On Delete +### 6.3 On Delete 1. Stop running jobs 2. Remove from cache @@ -535,6 +525,47 @@ type Action struct { 4. Delete or archive KB 5. Soft delete record +### 6.4 Execution Flow + +Single execution flow, depends on trigger type: + +```mermaid +flowchart LR + subgraph Trigger + T{Trigger} + end + + subgraph Schedule Path + P0[P0: Inspiration] + end + + subgraph Common Path + P1[P1: Goals] + P2[P2: Tasks] + P3[P3: Run] + P4[P4: Deliver] + P5[P5: Learn] + end + + T -->|Schedule| P0 + T -->|Human/Event| P1 + P0 --> P1 + P1 --> P2 --> P3 --> P4 --> P5 +``` + +```mermaid +stateDiagram-v2 + [*] --> Triggered + Triggered --> P0_Inspiration: Schedule + Triggered --> P1_Goals: Human/Event + P0_Inspiration --> P1_Goals + P1_Goals --> P2_Tasks + P2_Tasks --> P3_Run + P3_Run --> P4_Deliver + P4_Deliver --> P5_Learn + P5_Learn --> [*] +``` + --- ## 7. Integrations @@ -637,7 +668,7 @@ type State struct { StartTime time.Time EndTime *time.Time Status Status // pending | running | completed | failed - Phase Phase // inspiration | goal_gen | task_plan | run | deliver | learn + Phase Phase // inspiration (schedule only) | goal_gen | task_plan | run | deliver | learn Goals []Goal Tasks []Task Error string @@ -693,10 +724,10 @@ triggers: ```yaml resources: - p0: "__yao.inspiration" - p1: "__yao.goal-gen" - p2: "__yao.task-plan" - p3: "__yao.validator" + p0: "__yao.inspiration" # Schedule only + p1: "__yao.goals" + p2: "__yao.tasks" + p3: "__yao.validation" p4: "__yao.delivery" p5: "__yao.learning" ``` From 81cc25c6bb82110415ffb348de8fa1721545bce6 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 09:13:24 +0800 Subject: [PATCH 06/12] Update Execution Flow in Autonomous Agent Design Document to Include Trigger Decision Point - Added a decision point for triggers in the execution flow diagram, clarifying the paths for schedule and human/event triggers. - Revised the connections in the flowchart to reflect the new structure, ensuring a clear distinction between the Inspiration phase and goal generation based on trigger types. - Enhanced the overall clarity of the document by improving the representation of the agent's operational phases. --- agent/autonomous/DESIGN.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index eb81832d..52848eaa 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -40,7 +40,8 @@ flowchart TB end subgraph Executor["Executor"] - P0["P0: Inspiration
(Schedule only)"] + TT{"Trigger?"} + P0["P0: Inspiration"] P1["P1: Goals"] P2["P2: Tasks"] P3["P3: Run"] @@ -62,8 +63,9 @@ flowchart TB Dedup -->|OK| Queue Dedup -->|Dup| Cache Queue --> W1 & W2 & W3 - W1 --> P0 - W2 & W3 -.->|Human/Event| P1 + W1 & W2 & W3 --> TT + TT -->|Schedule| P0 + TT -->|Human/Event| P1 P0 --> P1 --> P2 --> P3 --> P4 --> P5 P5 --> KB & DB & Job KB -.->|History| P0 From 00517c64bd38f8d41fe4ad4871b0f790a5dd80db Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 09:36:51 +0800 Subject: [PATCH 07/12] Update Autonomous Agent Design Document to Replace Schedule with Clock Trigger - Changed terminology from "Schedule" to "Clock" throughout the document to reflect the new trigger type. - Revised flowcharts and diagrams to incorporate the clock context, clarifying the agent's operational phases based on time. - Updated configuration examples and descriptions to align with the new clock trigger settings, enhancing clarity on how agents operate under different timing modes. - Improved documentation for the Inspiration phase to specify its reliance on clock context, ensuring better understanding of the agent's decision-making process. --- agent/autonomous/DESIGN.md | 588 +++++++++++++++++++++++++++++++++---- 1 file changed, 539 insertions(+), 49 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index 52848eaa..36ea1754 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -21,7 +21,7 @@ An **Autonomous Agent** is an AI team member. It works on its own, makes decisio ```mermaid flowchart TB subgraph Triggers["Triggers"] - WC[/"โฐ Schedule"/] + WC[/"โฐ Clock"/] HI[/"๐Ÿ‘ค Human"/] EV[/"๐Ÿ“ก Event"/] end @@ -64,7 +64,7 @@ flowchart TB Dedup -->|Dup| Cache Queue --> W1 & W2 & W3 W1 & W2 & W3 --> TT - TT -->|Schedule| P0 + TT -->|Clock| P0 TT -->|Human/Event| P1 P0 --> P1 --> P2 --> P3 --> P4 --> P5 P5 --> KB & DB & Job @@ -138,8 +138,8 @@ sequenceDiagram W->>E: Run - alt Schedule trigger - E->>A: P0: Inspiration + alt Clock trigger + E->>A: P0: Inspiration (with clock context) A-->>E: Report end @@ -154,17 +154,17 @@ sequenceDiagram ### 3.2 Triggers -| Type | What | Config | -| ------------ | ------------------------ | -------------------- | -| **Schedule** | Timer (cron or interval) | `triggers.schedule` | -| **Human** | Manual action | `triggers.intervene` | -| **Event** | Webhook, DB change | `triggers.event` | +| Type | What | Config | +| --------- | ----------------------------- | -------------------- | +| **Clock** | Timer (times/interval/daemon) | `triggers.clock` | +| **Human** | Manual action | `triggers.intervene` | +| **Event** | Webhook, DB change | `triggers.event` | All on by default. Turn off per agent: ```yaml triggers: - schedule: { enabled: true } + clock: { enabled: true } intervene: { enabled: true, actions: ["add_task", "pause"] } event: { enabled: false } ``` @@ -219,27 +219,28 @@ type AgentCache struct { ### 4.1 Overview ``` -Schedule: P0 โ†’ P1 โ†’ P2 โ†’ P3 โ†’ P4 โ†’ P5 +Clock: P0 โ†’ P1 โ†’ P2 โ†’ P3 โ†’ P4 โ†’ P5 Human/Event: P1 โ†’ P2 โ†’ P3 โ†’ P4 โ†’ P5 ``` -| Phase | Agent | In | Out | When | -| ----- | ----------- | ---------------- | --------------- | ------------- | -| P0 | Inspiration | Data, news, time | Report | Schedule only | -| P1 | Goal Gen | Report + history | Goals | Always | -| P2 | Task Plan | Goals + tools | Tasks | Always | -| P3 | Validator | Results | Checked results | Always | -| P4 | Delivery | All results | Email/File | Always | -| P5 | Learning | Summary | KB entries | Always | +| Phase | Agent | In | Out | When | +| ----- | ----------- | ------------------- | --------------- | ---------- | +| P0 | Inspiration | Clock + Data + News | Report | Clock only | +| P1 | Goal Gen | Report + history | Goals | Always | +| P2 | Task Plan | Goals + tools | Tasks | Always | +| P3 | Validator | Results | Checked results | Always | +| P4 | Delivery | All results | Email/File | Always | +| P5 | Learning | Summary | KB entries | Always | -### 4.2 P0: Inspiration (Schedule only) +### 4.2 P0: Inspiration (Clock only) **Skipped for Human/Event triggers.** They already have clear intent. -Gathers info to help make good goals: +Gathers info to help make good goals. **Clock context is key input** - Agent knows what time it is and can decide what to do (e.g., 5pm Friday โ†’ write weekly report). ```go type InspirationReport struct { + Clock ClockContext // Current time context Summary string // What's happening Highlights []Highlight // Key changes Opportunities []Opportunity // Chances to act @@ -247,17 +248,29 @@ type InspirationReport struct { WorldInsights []WorldInsight // News from outside Suggestions []string // What to focus on } + +type ClockContext struct { + Now time.Time // Current time + Hour int // 0-23 + DayOfWeek string // Monday, Tuesday... + DayOfMonth int // 1-31 + IsWeekend bool + IsMonthStart bool // 1st-3rd + IsMonthEnd bool // last 3 days + IsQuarterEnd bool + // Agent uses this to decide: "It's 5pm Friday, time for weekly report" +} ``` **Sources:** +- **Clock**: Current time, day of week, month end, etc. - Internal: Data changes, events, feedback, pending work - External: Web search (news, competitors) -- Time: Day of week, deadlines ### 4.3 P1: Goals -**For Schedule:** Uses inspiration report to make goals. +**For Clock:** Uses inspiration report (with clock context) to make goals. Agent decides based on time what's important now. **For Human/Event:** Uses the input directly as goals (or to generate goals). @@ -331,7 +344,7 @@ Save to KB: ```go type Config struct { Triggers *Triggers `json:"triggers,omitempty"` - Schedule *Schedule `json:"schedule,omitempty"` + Clock *Clock `json:"clock,omitempty"` Identity *Identity `json:"identity"` Quota *Quota `json:"quota"` PrivateKB *KB `json:"private_kb"` @@ -349,7 +362,7 @@ type Config struct { ```go // Triggers - all on by default type Triggers struct { - Schedule *Trigger `json:"schedule,omitempty"` + Clock *Trigger `json:"clock,omitempty"` Intervene *Trigger `json:"intervene,omitempty"` Event *Trigger `json:"event,omitempty"` } @@ -359,14 +372,21 @@ type Trigger struct { Actions []string `json:"actions,omitempty"` // for intervene } -// Schedule -type Schedule struct { - Type string `json:"type"` // cron | interval - Expr string `json:"expr"` // "0 9 * * 1-5" or "1h" - TZ string `json:"tz"` - Timeout string `json:"timeout"` +// Clock - when to wake up +type Clock struct { + Mode string `json:"mode"` // "times" | "interval" | "daemon" + Times []string `json:"times"` // for mode=times: ["09:00", "14:00", "17:00"] + Days []string `json:"days"` // ["Mon", "Tue", "Wed", "Thu", "Fri"] or ["*"] + Every string `json:"every"` // for mode=interval: "30m", "1h" + TZ string `json:"tz"` // Asia/Shanghai + Timeout string `json:"timeout"` // max run time per execution } +// Clock modes: +// - times: Run at specific times (e.g., 9am, 2pm, 5pm) +// - interval: Run every X duration (e.g., every 30 minutes) +// - daemon: Run continuously (e.g., monitoring, data sync) + // Identity type Identity struct { Role string `json:"role"` @@ -396,7 +416,7 @@ type Learn struct { // Resources type Resources struct { - P0 string `json:"p0"` // Inspiration (Schedule only) + P0 string `json:"p0"` // Inspiration (Clock only) P1 string `json:"p1"` // Goals P2 string `json:"p2"` // Tasks P3 string `json:"p3"` // Validation @@ -446,13 +466,14 @@ type Action struct { "agent_id": "sales-bot", "agent_config": { "triggers": { - "schedule": { "enabled": true }, + "clock": { "enabled": true }, "intervene": { "enabled": true }, "event": { "enabled": false } }, - "schedule": { - "type": "cron", - "expr": "0 9 * * 1-5", + "clock": { + "mode": "times", + "times": ["09:00", "14:00", "17:00"], + "days": ["Mon", "Tue", "Wed", "Thu", "Fri"], "tz": "Asia/Shanghai", "timeout": "30m" }, @@ -549,7 +570,7 @@ flowchart LR P5[P5: Learn] end - T -->|Schedule| P0 + T -->|Clock| P0 T -->|Human/Event| P1 P0 --> P1 P1 --> P2 --> P3 --> P4 --> P5 @@ -558,7 +579,7 @@ flowchart LR ```mermaid stateDiagram-v2 [*] --> Triggered - Triggered --> P0_Inspiration: Schedule + Triggered --> P0_Inspiration: Clock Triggered --> P1_Goals: Human/Event P0_Inspiration --> P1_Goals P1_Goals --> P2_Tasks @@ -624,7 +645,7 @@ Made on agent create: `agent_{team_id}_{agent_id}_kb` **Types:** -- `schedule`: Timer +- `clock`: Timer (with time context) - `intervene`: Human action - `event`: Webhook, DB change - `callback`: Async result @@ -670,7 +691,7 @@ type State struct { StartTime time.Time EndTime *time.Time Status Status // pending | running | completed | failed - Phase Phase // inspiration (schedule only) | goal_gen | task_plan | run | deliver | learn + Phase Phase // inspiration (clock only) | goal_gen | task_plan | run | deliver | learn Goals []Goal Tasks []Task Error string @@ -717,16 +738,40 @@ CREATE TABLE autonomous_executions ( ```yaml triggers: - schedule: { enabled: true } + clock: { enabled: true } intervene: { enabled: true, actions: [...] } event: { enabled: false } ``` +### Clock + +```yaml +# Mode 1: Specific times +clock: + mode: times + times: ["09:00", "14:00", "17:00"] + days: ["Mon", "Tue", "Wed", "Thu", "Fri"] + tz: Asia/Shanghai + timeout: 30m + +# Mode 2: Interval +clock: + mode: interval + every: 30m # run every 30 minutes + timeout: 10m + +# Mode 3: Daemon (continuous monitoring/sync) +clock: + mode: daemon # restart immediately after each run + timeout: 5m # max time per run + # Use case: Data sync agent, system monitor agent +``` + ### Phase Agents ```yaml resources: - p0: "__yao.inspiration" # Schedule only + p0: "__yao.inspiration" # Clock only p1: "__yao.goals" p2: "__yao.tasks" p3: "__yao.validation" @@ -743,12 +788,457 @@ quota: priority: 5 # 1-10 ``` -### Schedule +--- -```yaml -schedule: - type: cron - expr: "0 9 * * 1-5" - tz: Asia/Shanghai - timeout: 30m +## 11. Examples + +Each example shows a different trigger mode: + +| Example | Trigger | Mode | Scenario | +| ------- | ------- | --------- | -------------------------------------------- | +| 11.1 | Clock | times | SEO/GEO Content - daily content optimization | +| 11.2 | Clock | interval | Competitor Monitor - check every 2 hours | +| 11.3 | Clock | daemon | Research Analyst - continuous insight mining | +| 11.4 | Human | intervene | Sales Assistant - manager assigns tasks | +| 11.5 | Event | event | Expense Processor - process new submissions | + +--- + +### 11.1 SEO/GEO Content Agent (Clock: times) + +**Trigger:** Clock - specific times daily + +**Role:** AI Marketing - auto-generate and optimize SEO/GEO content. + +```json +{ + "agent_id": "seo-content", + "agent_config": { + "triggers": { + "clock": { "enabled": true }, + "intervene": { "enabled": true } + }, + "clock": { + "mode": "times", + "times": ["06:00", "18:00"], + "days": ["Mon", "Tue", "Wed", "Thu", "Fri"], + "tz": "Asia/Shanghai" + }, + "identity": { + "role": "SEO/GEO Content Specialist", + "duties": [ + "Research trending keywords in our industry", + "Generate SEO-optimized articles (2-3 per day)", + "Optimize existing content for GEO (AI search)", + "Track keyword rankings and adjust strategy", + "A/B test titles and meta descriptions" + ] + }, + "resources": { + "agents": ["keyword-researcher", "content-writer", "seo-optimizer"], + "mcp": [ + { "id": "google-search", "tools": ["trends", "rankings"] }, + { "id": "cms", "tools": ["create", "update", "publish"] } + ] + }, + "delivery": { + "type": "notify", + "opts": { "channel": "marketing-team" } + } + } +} +``` + +**Example run at 06:00 Monday:** + +``` +P0 Inspiration: + Clock: Monday 06:00, start of week + Data: + - Keyword "AIๅบ”็”จๅผ€ๅ‘" trending (+45% this week) + - Our article ranks #8, competitor #2 + - 3 articles need GEO optimization + World: New AI regulation announced last Friday + +P1 Goals: + 1. Write new article targeting "AIๅบ”็”จๅผ€ๅ‘" + 2. Optimize 3 old articles for GEO + 3. Update meta descriptions for top 5 pages + +P2 Tasks: + 1. Research "AIๅบ”็”จๅผ€ๅ‘" keywords โ†’ keyword-researcher + 2. Write article with SEO structure โ†’ content-writer + 3. Add FAQ schema for GEO โ†’ seo-optimizer + 4. Publish to CMS โ†’ cms.publish + +P4 Delivery: + โ†’ Notify: "Published: 'AIๅบ”็”จๅผ€ๅ‘ๅฎŒๆ•ดๆŒ‡ๅ—' - targeting 12 keywords" + +P5 Learn: + - "AIๅบ”็”จๅผ€ๅ‘" articles perform well on Monday morning + - FAQ schema improves GEO visibility by 30% +``` + +--- + +### 11.2 Competitor Monitor (Clock: interval) + +**Trigger:** Clock - every 2 hours + +**Role:** Monitor competitors, track market changes, alert on important updates. + +```json +{ + "agent_id": "competitor-monitor", + "agent_config": { + "triggers": { + "clock": { "enabled": true } + }, + "clock": { + "mode": "interval", + "every": "2h" + }, + "identity": { + "role": "Competitor Intelligence Analyst", + "duties": [ + "Monitor competitor websites for changes", + "Track competitor pricing updates", + "Watch for new product launches", + "Analyze competitor content strategy", + "Alert team on significant changes" + ] + }, + "resources": { + "agents": ["web-scraper", "diff-analyzer", "report-writer"], + "mcp": [{ "id": "web-search", "tools": ["search", "news"] }] + }, + "delivery": { + "type": "webhook", + "opts": { "url": "https://slack.com/webhook/competitor-alerts" } + } + } +} +``` + +**Example run detecting competitor change:** + +``` +P0 Inspiration: + Clock: Tuesday 14:00 + Data: + - Competitor A: pricing page changed + - Competitor B: new blog post about "AI agents" + - Competitor C: no changes + +P1 Goals: + 1. Analyze Competitor A pricing change + 2. Summarize Competitor B's new content + 3. Assess impact on our positioning + +P2 Tasks: + 1. Scrape old vs new pricing โ†’ web-scraper + 2. Compare pricing tiers โ†’ diff-analyzer + 3. Generate competitive analysis โ†’ report-writer + +P3 Execute: + - Competitor A: dropped price 20% on enterprise tier + - Competitor B: targeting same keywords as us + +P4 Delivery: + โ†’ Slack: "๐Ÿšจ Competitor A cut enterprise price 20% - review needed" + +P5 Learn: + - Competitor A tends to change pricing on Tuesdays + - Price changes often precede feature launches +``` + +--- + +### 11.3 Industry Research Analyst (Clock: daemon) + +**Trigger:** Clock - continuous daemon mode + +**Role:** Continuously read industry news, papers, social media; extract insights; build knowledge. + +```json +{ + "agent_id": "research-analyst", + "agent_config": { + "triggers": { + "clock": { "enabled": true } + }, + "clock": { + "mode": "daemon", + "timeout": "10m" + }, + "identity": { + "role": "Industry Research Analyst", + "duties": [ + "Continuously scan industry news and papers", + "Analyze trends and extract key insights", + "Identify emerging technologies and competitors", + "Build and maintain industry knowledge base", + "Alert team on significant developments" + ] + }, + "resources": { + "agents": ["content-reader", "insight-extractor", "report-writer"], + "mcp": [ + { "id": "web-search", "tools": ["search", "news"] }, + { "id": "arxiv", "tools": ["search", "fetch"] }, + { "id": "twitter", "tools": ["search", "trends"] } + ] + }, + "delivery": { + "type": "notify", + "opts": { "channel": "research-insights" } + } + } +} +``` + +**Example continuous run:** + +``` +Run #1 (09:00): + P0: Scan sources + - 15 new AI news articles + - 3 new papers on arXiv + - Twitter: "AI Agent" trending + P1: Goals: + 1. Read and analyze new content + 2. Extract insights relevant to our business + 3. Update knowledge base + P2: Tasks: + 1. Read articles โ†’ content-reader + 2. Analyze papers โ†’ content-reader + 3. Extract insights โ†’ insight-extractor + P3: Execute: + - Article: "OpenAI releases new agent framework" + Insight: Validates our direction, watch for API changes + - Paper: "Multi-agent collaboration patterns" + Insight: Useful for our agent design, save to KB + - Twitter: Sentiment positive on AI agents + P4: Notify: "๐Ÿ“š 3 new insights added to KB" + P5: Learn: OpenAI news = high relevance, prioritize + โ†’ Restart immediately + +Run #2 (09:12): + P0: Scan sources + - 2 new articles (low relevance) + - No new papers + - Twitter: Normal activity + P1: Low-value content, skip deep analysis + P5: Learn: Mid-morning usually quiet + โ†’ Restart immediately + +Run #3 (09:25): + P0: Scan sources + - Breaking: "Competitor X raises $100M for AI platform" + P1: Goals: + 1. Deep analyze competitor news + 2. Assess impact on our market + 3. Alert team immediately + P2: Tasks: + 1. Gather all competitor X info โ†’ web-search + 2. Analyze their positioning โ†’ insight-extractor + 3. Write competitive brief โ†’ report-writer + P3: Execute: + - Competitor X: Focus on enterprise, similar target market + - Funding: Will likely expand sales team + - Threat level: Medium-High + P4: Notify: "๐Ÿšจ Competitor X raised $100M - brief attached" + P5: Learn: Funding news = always high priority + โ†’ Restart immediately +``` + +--- + +### 11.4 Sales Assistant (Human: intervene) + +**Trigger:** Human intervention - sales manager assigns tasks + +**Role:** Help sales team with research, proposals, follow-ups when manager assigns work. + +```json +{ + "agent_id": "sales-assistant", + "agent_config": { + "triggers": { + "clock": { "enabled": false }, + "intervene": { + "enabled": true, + "actions": ["add_task", "adjust_goal", "pause"] + } + }, + "identity": { + "role": "Sales Assistant", + "duties": [ + "Research assigned prospects and companies", + "Prepare customized proposals and presentations", + "Draft follow-up emails", + "Analyze deal history and suggest strategies", + "Prepare meeting briefs" + ] + }, + "resources": { + "agents": ["company-researcher", "proposal-writer", "email-drafter"], + "mcp": [ + { "id": "crm", "tools": ["query", "update"] }, + { "id": "linkedin", "tools": ["search", "profile"] }, + { "id": "email", "tools": ["draft", "send"] } + ] + }, + "delivery": { + "type": "email", + "opts": { "to": ["sales-manager@company.com"] } + } + } +} +``` + +**Example: Sales manager assigns task:** + +``` +Sales Manager Input: + Action: add_task + Description: "Meeting with BigCorp CTO tomorrow. Prepare materials. + They do smart manufacturing, $150M revenue, digital transformation." + +Agent Execution (no P0 for human trigger): + P1 Goals (from human input): + 1. Research BigCorp and their CTO + 2. Prepare meeting brief + 3. Draft customized proposal + + P2 Tasks: + 1. Research BigCorp โ†’ company-researcher + - Company background, recent news + - Digital transformation status + - Potential pain points + 2. Research CTO profile โ†’ linkedin.profile + - Background, interests + - Recent posts/articles + 3. Prepare meeting brief โ†’ proposal-writer + 4. Draft proposal โ†’ proposal-writer + + P3 Execute: + - BigCorp: Leading smart manufacturing, 3 factories, implementing MES + - CTO John: Ex-Google, focused on AI+Manufacturing, recent post on "AI QC" + - Pain point: High QC labor cost, 2% defect miss rate + - Opportunity: Our AI QC solution can reduce miss rate to 0.1% + + P4 Delivery: + โ†’ Email to sales manager: + - Attachment 1: BigCorp Research Report (PDF) + - Attachment 2: CTO Profile Brief + - Attachment 3: Custom Proposal - AI QC Solution + - Attachment 4: Meeting Agenda Suggestion + +Sales Manager Follow-up: + Action: add_task + Description: "Also prepare some similar case studies, manufacturing preferred" + +Agent Continues: + P1: Find similar manufacturing case studies + P2: Search CRM for manufacturing wins + P3: Found 3 cases: Auto parts factory, Electronics plant, Food processing + P4: Email: "3 manufacturing case studies attached" +``` + +--- + +### 11.5 Lead Processor (Event: webhook) + +**Trigger:** Event - new lead from website/CRM + +**Role:** Instantly process and qualify new leads, route to sales. + +```json +{ + "agent_id": "lead-processor", + "agent_config": { + "triggers": { + "clock": { "enabled": false }, + "event": { "enabled": true } + }, + "events": [ + { + "type": "webhook", + "source": "/webhook/leads", + "filter": { "event_types": ["lead.created"] } + }, + { + "type": "database", + "source": "crm_leads", + "filter": { "trigger": "insert" } + } + ], + "identity": { + "role": "Lead Qualification Specialist", + "duties": [ + "Instantly process new leads", + "Enrich lead data (company info, LinkedIn)", + "Score lead quality (1-100)", + "Route hot leads to sales immediately", + "Add cold leads to nurture sequence" + ] + }, + "resources": { + "agents": ["data-enricher", "lead-scorer"], + "mcp": [ + { "id": "clearbit", "tools": ["enrich"] }, + { "id": "crm", "tools": ["update", "assign"] }, + { "id": "email", "tools": ["send"] } + ] + }, + "delivery": { + "type": "webhook", + "opts": { "url": "https://slack.com/webhook/sales-leads" } + } + } +} +``` + +**Example: New lead event:** + +``` +Event Received: + Type: lead.created + Data: { + name: "John Smith", + email: "john@bigcorp.com", + company: "BigCorp", + message: "Interested in Enterprise pricing, team of 50" + } + +Agent Execution (no P0 for events): + P1 Goals: + 1. Enrich lead data + 2. Score lead quality + 3. Route appropriately + + P2 Tasks: + 1. Lookup company info โ†’ clearbit.enrich + 2. Calculate lead score โ†’ lead-scorer + 3. Update CRM โ†’ crm.update + 4. Notify sales โ†’ slack webhook + + P3 Execute: + - Company: BigCorp, 500 employees, Series C + - LinkedIn: VP of Engineering + - Lead Score: 85/100 (HOT) + - Reason: Enterprise inquiry, decision maker, funded company + + P4 Delivery: + โ†’ Slack: "๐Ÿ”ฅ HOT LEAD (85/100): John Smith @ BigCorp + - 500 employees, Series C + - Interested in Enterprise (50 seats) + - Assigned to: Sales Rep A" + โ†’ CRM: Lead updated, assigned to Sales Rep A + โ†’ Email to lead: "Thanks for your inquiry. Our sales rep will contact you within 1 hour." + + P5 Learn: + - BigCorp profile saved for future reference + - VP-level leads from funded companies = high conversion ``` From 0a58bfdddf1887e51fae26cc55a2748cc70d4535 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 09:46:30 +0800 Subject: [PATCH 08/12] Update Autonomous Agent Design Document to Clarify Daemon Mode and Terminology - Revised the description of the daemon mode to reflect its use cases as "research analyst" and "market monitor." - Updated configuration examples to align with the new terminology, enhancing clarity on the agent's operational context. - Corrected terminology for keywords in the P0 and P1 phases to improve consistency and understanding of the target audience. - Added a new execution phase (P3) detailing the article's execution and publication process, providing a clearer overview of the agent's tasks. --- agent/autonomous/DESIGN.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index 36ea1754..a8996466 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -385,7 +385,7 @@ type Clock struct { // Clock modes: // - times: Run at specific times (e.g., 9am, 2pm, 5pm) // - interval: Run every X duration (e.g., every 30 minutes) -// - daemon: Run continuously (e.g., monitoring, data sync) +// - daemon: Run continuously (e.g., research analyst, market monitor) // Identity type Identity struct { @@ -760,11 +760,11 @@ clock: every: 30m # run every 30 minutes timeout: 10m -# Mode 3: Daemon (continuous monitoring/sync) +# Mode 3: Daemon (continuous thinking/analysis) clock: mode: daemon # restart immediately after each run - timeout: 5m # max time per run - # Use case: Data sync agent, system monitor agent + timeout: 10m # max time per run + # Use case: Research analyst, market monitor ``` ### Phase Agents @@ -800,7 +800,7 @@ Each example shows a different trigger mode: | 11.2 | Clock | interval | Competitor Monitor - check every 2 hours | | 11.3 | Clock | daemon | Research Analyst - continuous insight mining | | 11.4 | Human | intervene | Sales Assistant - manager assigns tasks | -| 11.5 | Event | event | Expense Processor - process new submissions | +| 11.5 | Event | webhook | Lead Processor - qualify and route new leads | --- @@ -855,27 +855,32 @@ Each example shows a different trigger mode: P0 Inspiration: Clock: Monday 06:00, start of week Data: - - Keyword "AIๅบ”็”จๅผ€ๅ‘" trending (+45% this week) + - Keyword "AI app development" trending (+45% this week) - Our article ranks #8, competitor #2 - 3 articles need GEO optimization World: New AI regulation announced last Friday P1 Goals: - 1. Write new article targeting "AIๅบ”็”จๅผ€ๅ‘" + 1. Write new article targeting "AI app development" 2. Optimize 3 old articles for GEO 3. Update meta descriptions for top 5 pages P2 Tasks: - 1. Research "AIๅบ”็”จๅผ€ๅ‘" keywords โ†’ keyword-researcher + 1. Research "AI app development" keywords โ†’ keyword-researcher 2. Write article with SEO structure โ†’ content-writer 3. Add FAQ schema for GEO โ†’ seo-optimizer 4. Publish to CMS โ†’ cms.publish +P3 Execute: + - Keywords: "AI app development", "build AI apps", "AI dev guide" (12 total) + - Article: 2500 words, 8 sections, FAQ schema added + - Published to CMS, indexed by Google + P4 Delivery: - โ†’ Notify: "Published: 'AIๅบ”็”จๅผ€ๅ‘ๅฎŒๆ•ดๆŒ‡ๅ—' - targeting 12 keywords" + โ†’ Notify: "Published: 'Complete Guide to AI App Development' - targeting 12 keywords" P5 Learn: - - "AIๅบ”็”จๅผ€ๅ‘" articles perform well on Monday morning + - "AI app development" articles perform well on Monday morning - FAQ schema improves GEO visibility by 30% ``` @@ -1144,6 +1149,7 @@ Agent Continues: P2: Search CRM for manufacturing wins P3: Found 3 cases: Auto parts factory, Electronics plant, Food processing P4: Email: "3 manufacturing case studies attached" + P5: Learn: Manufacturing prospects often need QC case studies ``` --- From e318455bc2b63e8d956fae9f4e07fa8e917fd82f Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 10:02:55 +0800 Subject: [PATCH 09/12] Add Execution Phases and Enums to Autonomous Agent Design Document - Introduced new enums for execution phases, clock modes, delivery types, and statuses to enhance clarity and structure. - Updated the `Clock` struct to use the new `ClockMode` type, improving type safety and readability. - Revised the `Resources` struct to utilize a map for phases, allowing for more flexible resource management. - Enhanced the `Delivery` struct to incorporate the new `DeliveryType` enum, clarifying output options. - Updated the design document to reflect these changes, improving overall organization and understanding of the agent's operational context. --- agent/autonomous/DESIGN.md | 232 ++++++++++++++++++++++++++----------- 1 file changed, 164 insertions(+), 68 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index a8996466..4cf34bc2 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -360,6 +360,53 @@ type Config struct { ### 5.2 Types ```go +// Phase - execution phase enum +type Phase string + +const ( + PhaseInspiration Phase = "inspiration" // P0: Clock only + PhaseGoals Phase = "goals" // P1 + PhaseTasks Phase = "tasks" // P2 + PhaseValidation Phase = "validation" // P3 + PhaseDelivery Phase = "delivery" // P4 + PhaseLearning Phase = "learning" // P5 +) + +// AllPhases for iteration +var AllPhases = []Phase{ + PhaseInspiration, PhaseGoals, PhaseTasks, + PhaseValidation, PhaseDelivery, PhaseLearning, +} + +// ClockMode - clock trigger mode enum +type ClockMode string + +const ( + ClockModeTimes ClockMode = "times" // run at specific times + ClockModeInterval ClockMode = "interval" // run every X duration + ClockModeDaemon ClockMode = "daemon" // run continuously +) + +// DeliveryType - output delivery type enum +type DeliveryType string + +const ( + DeliveryEmail DeliveryType = "email" + DeliveryFile DeliveryType = "file" + DeliveryWebhook DeliveryType = "webhook" + DeliveryNotify DeliveryType = "notify" +) + +// Status - execution status enum +type Status string + +const ( + StatusPending Status = "pending" + StatusRunning Status = "running" + StatusCompleted Status = "completed" + StatusFailed Status = "failed" +) + // Triggers - all on by default type Triggers struct { Clock *Trigger `json:"clock,omitempty"` @@ -374,19 +421,14 @@ type Trigger struct { // Clock - when to wake up type Clock struct { - Mode string `json:"mode"` // "times" | "interval" | "daemon" - Times []string `json:"times"` // for mode=times: ["09:00", "14:00", "17:00"] - Days []string `json:"days"` // ["Mon", "Tue", "Wed", "Thu", "Fri"] or ["*"] - Every string `json:"every"` // for mode=interval: "30m", "1h" - TZ string `json:"tz"` // Asia/Shanghai - Timeout string `json:"timeout"` // max run time per execution + Mode ClockMode `json:"mode"` + Times []string `json:"times"` // for times: ["09:00", "14:00"] + Days []string `json:"days"` // ["Mon", "Tue"...] or ["*"] + Every string `json:"every"` // for interval: "30m", "1h" + TZ string `json:"tz"` // Asia/Shanghai + Timeout string `json:"timeout"` // max run time } -// Clock modes: -// - times: Run at specific times (e.g., 9am, 2pm, 5pm) -// - interval: Run every X duration (e.g., every 30 minutes) -// - daemon: Run continuously (e.g., research analyst, market monitor) - // Identity type Identity struct { Role string `json:"role"` @@ -416,14 +458,9 @@ type Learn struct { // Resources type Resources struct { - P0 string `json:"p0"` // Inspiration (Clock only) - P1 string `json:"p1"` // Goals - P2 string `json:"p2"` // Tasks - P3 string `json:"p3"` // Validation - P4 string `json:"p4"` // Delivery - P5 string `json:"p5"` // Learning - Agents []string `json:"agents"` - MCP []MCP `json:"mcp"` + Phases map[Phase]string `json:"phases,omitempty"` // optional, defaults to __yao.{phase} + Agents []string `json:"agents"` + MCP []MCP `json:"mcp"` } type MCP struct { @@ -433,7 +470,7 @@ type MCP struct { // Delivery type Delivery struct { - Type string `json:"type"` // email | file | webhook | notify + Type DeliveryType `json:"type"` Opts map[string]interface{} `json:"opts"` } @@ -492,12 +529,14 @@ type Action struct { }, "shared_kb": { "refs": ["sales-policies", "products"] }, "resources": { - "p0": "__yao.inspiration", - "p1": "__yao.goals", - "p2": "__yao.tasks", - "p3": "__yao.validation", - "p4": "__yao.delivery", - "p5": "__yao.learning", + "phases": { + "inspiration": "__yao.inspiration", + "goals": "__yao.goals", + "tasks": "__yao.tasks", + "validation": "__yao.validation", + "delivery": "__yao.delivery", + "learning": "__yao.learning" + }, "agents": ["data-analyst", "chart-gen"], "mcp": [{ "id": "database", "tools": ["query"] }] }, @@ -667,59 +706,114 @@ Made on agent create: `agent_{team_id}_{agent_id}_kb` ## 8. API -### 8.1 Manager +### 8.1 Manager (Internal) ```go type Manager interface { + // Lifecycle Start() error Stop() error - LoadActiveAgents(ctx context.Context) ([]*Agent, error) - ShouldExecute(agent *Agent, now time.Time) bool - Execute(ctx context.Context, agent *Agent) (*State, error) - Trigger(ctx context.Context, teamID, agentID string) (*State, error) - GetHistory(ctx context.Context, teamID, agentID string, limit int) ([]*State, error) + + // Cache + LoadActiveAgents(ctx context.Context) error + GetAgent(teamID, agentID string) *Agent + + // Clock trigger (internal, called by ticker) + Tick(ctx context.Context, now time.Time) error } ``` -### 8.2 State +### 8.2 Trigger (Called by openapi layer) ```go -type State struct { - ID string - TeamID string +// TriggerType enum +type TriggerType string + +const ( + TriggerClock TriggerType = "clock" + TriggerHuman TriggerType = "human" + TriggerEvent TriggerType = "event" +) + +// Trigger interface - called by openapi handlers +type Trigger interface { + // Human intervention + Intervene(ctx context.Context, req InterveneRequest) (*ExecutionResult, error) + + // Event trigger (webhook, db change) + HandleEvent(ctx context.Context, req EventRequest) (*ExecutionResult, error) + + // Query & control + GetStatus(ctx context.Context, teamID, agentID string) (*AgentStatus, error) + Pause(ctx context.Context, teamID, agentID string) error + Resume(ctx context.Context, teamID, agentID string) error +} + +type InterveneRequest struct { + TeamID string + AgentID string + Action string // add_task | adjust_goal | cancel_task | pause | resume | abort | plan + Description string + Priority string // high | normal | low + PlanTime time.Time // for action=plan +} + +type EventRequest struct { AgentID string - StartTime time.Time - EndTime *time.Time - Status Status // pending | running | completed | failed - Phase Phase // inspiration (clock only) | goal_gen | task_plan | run | deliver | learn - Goals []Goal - Tasks []Task - Error string - Result interface{} + Source string // webhook path or table name + EventType string // lead.created, etc. + Data map[string]interface{} +} + +type ExecutionResult struct { + ExecutionID string // Job execution ID + Status Status +} + +type AgentStatus struct { + AgentID string + Status string // active | paused | running + LastRun time.Time + NextRun time.Time + RunningID string // current execution ID if running } ``` -### 8.3 Database +### 8.4 Execution (Uses Job System) -```sql -CREATE TABLE autonomous_executions ( - id VARCHAR(64) PRIMARY KEY, - team_id VARCHAR(64) NOT NULL, - agent_id VARCHAR(64) NOT NULL, - start_time DATETIME NOT NULL, - end_time DATETIME, - status VARCHAR(32) NOT NULL, - phase VARCHAR(32), - goals JSON, - tasks JSON, - error TEXT, - result JSON, - created_at DATETIME DEFAULT CURRENT_TIMESTAMP, - INDEX idx_team_agent (team_id, agent_id), - INDEX idx_status (status) -); +No separate `autonomous_executions` table. Uses existing Job system: + +```go +// On agent create +job.Create(Job{ + ID: "agent_" + agentID, + CategoryID: "autonomous_agent", + Name: agent.Identity.Role, + Handler: "autonomous.Execute", + Args: map[string]interface{}{"agent_id": agentID}, +}) + +// On trigger (clock/human/event) +job.Push(jobID, ExecutionArgs{ + TriggerType: TriggerClock, // or TriggerHuman, TriggerEvent + TriggerData: data, +}) + +// Query history +executions := job.GetExecutions(jobID, limit) +logs := job.GetLogs(executionID) ``` +**Job APIs for monitoring:** + +| Action | API | +| ------- | ------------------------------------------- | +| List | `GET /api/jobs?category=autonomous_agent` | +| Status | `GET /api/jobs/:job_id` | +| History | `GET /api/jobs/:job_id/executions` | +| Logs | `GET /api/jobs/:job_id/executions/:id/logs` | +| Cancel | `POST /api/jobs/:job_id/cancel` | + --- ## 9. Security @@ -770,13 +864,15 @@ clock: ### Phase Agents ```yaml +# Optional - defaults to __yao.{phase} if not specified resources: - p0: "__yao.inspiration" # Clock only - p1: "__yao.goals" - p2: "__yao.tasks" - p3: "__yao.validation" - p4: "__yao.delivery" - p5: "__yao.learning" + phases: + inspiration: "__yao.inspiration" # Clock only + goals: "__yao.goals" + tasks: "__yao.tasks" + validation: "__yao.validation" + delivery: "__yao.delivery" + learning: "__yao.learning" ``` ### Quota From b19597808ddd36840248146c99d54fbd58074914 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 10:05:46 +0800 Subject: [PATCH 10/12] Refactor Execution Status and Agent State Enums in Design Document - Renamed the `Status` type to `ExecStatus` for clarity in execution status representation. - Introduced a new `AgentState` type to define the operational states of the agent, enhancing the structure of the design document. - Updated relevant sections to reflect these changes, improving overall readability and understanding of the agent's execution and operational context. --- agent/autonomous/DESIGN.md | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index 4cf34bc2..04082b01 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -397,14 +397,23 @@ const ( DeliveryNotify DeliveryType = "notify" ) -// Status - execution status enum -type Status string +// ExecStatus - execution status enum +type ExecStatus string const ( - StatusPending Status = "pending" - StatusRunning Status = "running" - StatusCompleted Status = "completed" - StatusFailed Status = "failed" + ExecPending ExecStatus = "pending" + ExecRunning ExecStatus = "running" + ExecCompleted ExecStatus = "completed" + ExecFailed ExecStatus = "failed" +) + +// AgentState - agent operational state enum +type AgentState string + +const ( + AgentActive AgentState = "active" // ready to run + AgentPaused AgentState = "paused" // manually paused + AgentRunning AgentState = "running" // currently executing ) // Triggers - all on by default @@ -766,13 +775,13 @@ type EventRequest struct { } type ExecutionResult struct { - ExecutionID string // Job execution ID - Status Status + ExecutionID string // Job execution ID + Status ExecStatus // pending | running | completed | failed } type AgentStatus struct { AgentID string - Status string // active | paused | running + State AgentState // active | paused | running LastRun time.Time NextRun time.Time RunningID string // current execution ID if running From d7d6f1b77b8dbdb84f9bbc94163ce54dc7d37bc5 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 10:16:58 +0800 Subject: [PATCH 11/12] Refactor Autonomous Agent Design Document to Update Terminology and Structure - Replaced references to "AI Members" with "Robot Members" and "Human Members" with "User Members" for clarity. - Updated the `team_members` table description to reflect the use of the `__yao.member` model, enhancing consistency in terminology. - Revised key fields and examples in the document to align with the new member structure, improving overall understanding of the agent's configuration and operational context. - Enhanced flowcharts and diagrams to accurately represent the updated member types and their roles within the team structure. --- agent/autonomous/DESIGN.md | 450 +++++++++++++++++++------------------ 1 file changed, 230 insertions(+), 220 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index 04082b01..fe83660e 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -73,13 +73,13 @@ flowchart TB ### 2.2 Team Structure -AI members live in `team_members` table with `member_type = "ai"`: +Uses existing `__yao.member` model (`yao/models/member.mod.yao`): ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Team โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ AI Members โ”‚ โ”‚ +โ”‚ โ”‚ Robot Members โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚Sales Managerโ”‚ โ”‚Data Analyst โ”‚ โ”‚CS Specialistโ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ€ข Track KPIsโ”‚ โ”‚ โ€ข Analyze โ”‚ โ”‚ โ€ข Tickets โ”‚ โ”‚ โ”‚ @@ -87,7 +87,7 @@ AI members live in `team_members` table with `member_type = "ai"`: โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ -โ”‚ โ”‚ Human Members โ”‚ โ”‚ +โ”‚ โ”‚ User Members โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ John (Owner)โ”‚ โ”‚ Jane (Admin)โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ @@ -95,19 +95,18 @@ AI members live in `team_members` table with `member_type = "ai"`: โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` -```sql -CREATE TABLE team_members ( - id BIGINT PRIMARY KEY AUTO_INCREMENT, - team_id VARCHAR(64) NOT NULL, - user_id VARCHAR(64), -- for humans - member_type VARCHAR(32) NOT NULL, -- "user" | "ai" - agent_id VARCHAR(64), -- for AI only - agent_config JSON, -- AI config - status VARCHAR(32) DEFAULT 'active', - INDEX idx_team_id (team_id), - INDEX idx_agent_id (agent_id) -); -``` +**Key fields in `__yao.member` for autonomous agents:** + +| Field | Type | Description | +| ----------------- | ------ | ----------------------------------------------------------- | +| `member_type` | enum | `user` \| `robot` | +| `autonomous_mode` | bool | Enable autonomous execution | +| `robot_config` | JSON | Agent configuration (see section 5) | +| `robot_status` | enum | `idle` \| `working` \| `paused` \| `error` \| `maintenance` | +| `system_prompt` | text | Identity & role prompt | +| `agents` | JSON | Accessible agents list | +| `mcp_servers` | JSON | Accessible MCP servers | +| `manager_id` | string | Direct manager user ID | --- @@ -191,7 +190,7 @@ Two levels to prevent one agent from using all resources: **Fast check** (in memory): ```go -key := agentID + ":" + triggerType + ":" + window +key := memberID + ":" + triggerType + ":" + window if has(key) { skip } ``` @@ -206,8 +205,8 @@ Keeps agents in memory. No DB query on each tick: ```go type AgentCache struct { - agents map[string]*Agent // agent_id -> agent - byTeam map[string][]string // team_id -> agent_ids + agents map[string]*Agent // member_id -> agent + byTeam map[string][]string // team_id -> member_ids } // Refresh: on start, on change, every hour ``` @@ -407,13 +406,15 @@ const ( ExecFailed ExecStatus = "failed" ) -// AgentState - agent operational state enum -type AgentState string +// RobotStatus - matches __yao.member.robot_status enum +type RobotStatus string const ( - AgentActive AgentState = "active" // ready to run - AgentPaused AgentState = "paused" // manually paused - AgentRunning AgentState = "running" // currently executing + RobotIdle RobotStatus = "idle" // ready to run + RobotWorking RobotStatus = "working" // currently executing + RobotPaused RobotStatus = "paused" // manually paused + RobotError RobotStatus = "error" // encountered error + RobotMaintenance RobotStatus = "maintenance" // under maintenance ) // Triggers - all on by default @@ -506,11 +507,18 @@ type Action struct { ### 5.3 Example +Example record in `__yao.member` table: + ```json { - "member_type": "ai", - "agent_id": "sales-bot", - "agent_config": { + "member_id": "mem_abc123", + "team_id": "team_xyz", + "member_type": "robot", + "display_name": "Sales Bot", + "autonomous_mode": true, + "robot_status": "idle", + "system_prompt": "You are a sales analyst...", + "robot_config": { "triggers": { "clock": { "enabled": true }, "intervene": { "enabled": true }, @@ -553,7 +561,9 @@ type Action struct { "type": "email", "opts": { "to": ["manager@company.com"] } } - } + }, + "agents": ["data-analyst", "chart-gen"], + "mcp_servers": ["database"] } ``` @@ -565,25 +575,35 @@ type Action struct { ```mermaid stateDiagram-v2 - [*] --> Active: POST create - Active --> Paused: PATCH pause - Paused --> Active: PATCH resume - Active --> [*]: DELETE + [*] --> Idle: POST create + Idle --> Working: trigger + Working --> Idle: done + Idle --> Paused: PATCH pause + Working --> Paused: PATCH pause + Paused --> Idle: PATCH resume + Idle --> Error: error + Working --> Error: error + Error --> Idle: PATCH reset + Idle --> [*]: DELETE Paused --> [*]: DELETE ``` -| From | To | How | -| ------ | ------- | --------------------- | -| - | active | POST create | -| active | paused | PATCH status="paused" | -| paused | active | PATCH status="active" | -| any | deleted | DELETE | +| From | To | How | +| ------- | ------- | --------------------------- | +| - | idle | POST create | +| idle | working | trigger (clock/human/event) | +| working | idle | execution done | +| idle | paused | PATCH robot_status="paused" | +| paused | idle | PATCH robot_status="idle" | +| any | error | execution error | +| error | idle | PATCH robot_status="idle" | +| any | deleted | DELETE | ### 6.2 On Create 1. Check config -2. Make agent_id if missing -3. Create KB: `agent_{team_id}_{agent_id}_kb` +2. Generate member_id if missing +3. Create KB: `robot_{team_id}_{member_id}_kb` 4. Add to cache 5. Create Job 6. Set active @@ -665,7 +685,7 @@ Each agent = 1 Job. Each run = 1 Execution. | Action | API | | -------- | -------------------------------------------- | -| List | `GET /api/jobs?category_id=autonomous_agent` | +| List | `GET /api/jobs?category_id=autonomous_robot` | | History | `GET /api/jobs/:job_id/executions` | | Progress | `GET /api/jobs/:job_id/executions/:id` | | Logs | `GET /api/jobs/:job_id/executions/:id/logs` | @@ -674,7 +694,7 @@ Each agent = 1 Job. Each run = 1 Execution. ### 7.2 Private KB -Made on agent create: `agent_{team_id}_{agent_id}_kb` +Made on robot member create: `robot_{team_id}_{member_id}_kb` **What it stores:** @@ -684,10 +704,10 @@ Made on agent create: `agent_{team_id}_{agent_id}_kb` **When:** -- Create: On agent create +- Create: On robot member create - Update: After P5 - Clean: Based on `keep` days -- Delete: On agent delete +- Delete: On robot member delete ### 7.3 External Input @@ -724,8 +744,8 @@ type Manager interface { Stop() error // Cache - LoadActiveAgents(ctx context.Context) error - GetAgent(teamID, agentID string) *Agent + LoadActiveRobots(ctx context.Context) error + GetRobot(teamID, memberID string) *Robot // Clock trigger (internal, called by ticker) Tick(ctx context.Context, now time.Time) error @@ -753,14 +773,14 @@ type Trigger interface { HandleEvent(ctx context.Context, req EventRequest) (*ExecutionResult, error) // Query & control - GetStatus(ctx context.Context, teamID, agentID string) (*AgentStatus, error) - Pause(ctx context.Context, teamID, agentID string) error - Resume(ctx context.Context, teamID, agentID string) error + GetStatus(ctx context.Context, teamID, memberID string) (*RobotState, error) + Pause(ctx context.Context, teamID, memberID string) error + Resume(ctx context.Context, teamID, memberID string) error } type InterveneRequest struct { TeamID string - AgentID string + MemberID string Action string // add_task | adjust_goal | cancel_task | pause | resume | abort | plan Description string Priority string // high | normal | low @@ -768,7 +788,7 @@ type InterveneRequest struct { } type EventRequest struct { - AgentID string + MemberID string Source string // webhook path or table name EventType string // lead.created, etc. Data map[string]interface{} @@ -779,12 +799,12 @@ type ExecutionResult struct { Status ExecStatus // pending | running | completed | failed } -type AgentStatus struct { - AgentID string - State AgentState // active | paused | running +type RobotState struct { + MemberID string // member_id from __yao.member + Status RobotStatus // idle | working | paused | error | maintenance LastRun time.Time NextRun time.Time - RunningID string // current execution ID if running + RunningID string // current execution ID if working } ``` @@ -793,13 +813,13 @@ type AgentStatus struct { No separate `autonomous_executions` table. Uses existing Job system: ```go -// On agent create +// On robot member create job.Create(Job{ - ID: "agent_" + agentID, - CategoryID: "autonomous_agent", - Name: agent.Identity.Role, + ID: "robot_" + memberID, + CategoryID: "autonomous_robot", + Name: member.DisplayName, Handler: "autonomous.Execute", - Args: map[string]interface{}{"agent_id": agentID}, + Args: map[string]interface{}{"member_id": memberID}, }) // On trigger (clock/human/event) @@ -817,7 +837,7 @@ logs := job.GetLogs(executionID) | Action | API | | ------- | ------------------------------------------- | -| List | `GET /api/jobs?category=autonomous_agent` | +| List | `GET /api/jobs?category=autonomous_robot` | | Status | `GET /api/jobs/:job_id` | | History | `GET /api/jobs/:job_id/executions` | | Logs | `GET /api/jobs/:job_id/executions/:id/logs` | @@ -916,40 +936,38 @@ Each example shows a different trigger mode: **Role:** AI Marketing - auto-generate and optimize SEO/GEO content. ```json +// robot_config for SEO Content Agent { - "agent_id": "seo-content", - "agent_config": { - "triggers": { - "clock": { "enabled": true }, - "intervene": { "enabled": true } - }, - "clock": { - "mode": "times", - "times": ["06:00", "18:00"], - "days": ["Mon", "Tue", "Wed", "Thu", "Fri"], - "tz": "Asia/Shanghai" - }, - "identity": { - "role": "SEO/GEO Content Specialist", - "duties": [ - "Research trending keywords in our industry", - "Generate SEO-optimized articles (2-3 per day)", - "Optimize existing content for GEO (AI search)", - "Track keyword rankings and adjust strategy", - "A/B test titles and meta descriptions" - ] - }, - "resources": { - "agents": ["keyword-researcher", "content-writer", "seo-optimizer"], - "mcp": [ - { "id": "google-search", "tools": ["trends", "rankings"] }, - { "id": "cms", "tools": ["create", "update", "publish"] } - ] - }, - "delivery": { - "type": "notify", - "opts": { "channel": "marketing-team" } - } + "triggers": { + "clock": { "enabled": true }, + "intervene": { "enabled": true } + }, + "clock": { + "mode": "times", + "times": ["06:00", "18:00"], + "days": ["Mon", "Tue", "Wed", "Thu", "Fri"], + "tz": "Asia/Shanghai" + }, + "identity": { + "role": "SEO/GEO Content Specialist", + "duties": [ + "Research trending keywords in our industry", + "Generate SEO-optimized articles (2-3 per day)", + "Optimize existing content for GEO (AI search)", + "Track keyword rankings and adjust strategy", + "A/B test titles and meta descriptions" + ] + }, + "resources": { + "agents": ["keyword-researcher", "content-writer", "seo-optimizer"], + "mcp": [ + { "id": "google-search", "tools": ["trends", "rankings"] }, + { "id": "cms", "tools": ["create", "update", "publish"] } + ] + }, + "delivery": { + "type": "notify", + "opts": { "channel": "marketing-team" } } } ``` @@ -998,34 +1016,32 @@ P5 Learn: **Role:** Monitor competitors, track market changes, alert on important updates. ```json +// robot_config for Competitor Monitor { - "agent_id": "competitor-monitor", - "agent_config": { - "triggers": { - "clock": { "enabled": true } - }, - "clock": { - "mode": "interval", - "every": "2h" - }, - "identity": { - "role": "Competitor Intelligence Analyst", - "duties": [ - "Monitor competitor websites for changes", - "Track competitor pricing updates", - "Watch for new product launches", - "Analyze competitor content strategy", - "Alert team on significant changes" - ] - }, - "resources": { - "agents": ["web-scraper", "diff-analyzer", "report-writer"], - "mcp": [{ "id": "web-search", "tools": ["search", "news"] }] - }, - "delivery": { - "type": "webhook", - "opts": { "url": "https://slack.com/webhook/competitor-alerts" } - } + "triggers": { + "clock": { "enabled": true } + }, + "clock": { + "mode": "interval", + "every": "2h" + }, + "identity": { + "role": "Competitor Intelligence Analyst", + "duties": [ + "Monitor competitor websites for changes", + "Track competitor pricing updates", + "Watch for new product launches", + "Analyze competitor content strategy", + "Alert team on significant changes" + ] + }, + "resources": { + "agents": ["web-scraper", "diff-analyzer", "report-writer"], + "mcp": [{ "id": "web-search", "tools": ["search", "news"] }] + }, + "delivery": { + "type": "webhook", + "opts": { "url": "https://slack.com/webhook/competitor-alerts" } } } ``` @@ -1071,38 +1087,36 @@ P5 Learn: **Role:** Continuously read industry news, papers, social media; extract insights; build knowledge. ```json +// robot_config for Research Analyst { - "agent_id": "research-analyst", - "agent_config": { - "triggers": { - "clock": { "enabled": true } - }, - "clock": { - "mode": "daemon", - "timeout": "10m" - }, - "identity": { - "role": "Industry Research Analyst", - "duties": [ - "Continuously scan industry news and papers", - "Analyze trends and extract key insights", - "Identify emerging technologies and competitors", - "Build and maintain industry knowledge base", - "Alert team on significant developments" - ] - }, - "resources": { - "agents": ["content-reader", "insight-extractor", "report-writer"], - "mcp": [ - { "id": "web-search", "tools": ["search", "news"] }, - { "id": "arxiv", "tools": ["search", "fetch"] }, - { "id": "twitter", "tools": ["search", "trends"] } - ] - }, - "delivery": { - "type": "notify", - "opts": { "channel": "research-insights" } - } + "triggers": { + "clock": { "enabled": true } + }, + "clock": { + "mode": "daemon", + "timeout": "10m" + }, + "identity": { + "role": "Industry Research Analyst", + "duties": [ + "Continuously scan industry news and papers", + "Analyze trends and extract key insights", + "Identify emerging technologies and competitors", + "Build and maintain industry knowledge base", + "Alert team on significant developments" + ] + }, + "resources": { + "agents": ["content-reader", "insight-extractor", "report-writer"], + "mcp": [ + { "id": "web-search", "tools": ["search", "news"] }, + { "id": "arxiv", "tools": ["search", "fetch"] }, + { "id": "twitter", "tools": ["search", "trends"] } + ] + }, + "delivery": { + "type": "notify", + "opts": { "channel": "research-insights" } } } ``` @@ -1171,38 +1185,36 @@ Run #3 (09:25): **Role:** Help sales team with research, proposals, follow-ups when manager assigns work. ```json +// robot_config for Sales Assistant { - "agent_id": "sales-assistant", - "agent_config": { - "triggers": { - "clock": { "enabled": false }, - "intervene": { - "enabled": true, - "actions": ["add_task", "adjust_goal", "pause"] - } - }, - "identity": { - "role": "Sales Assistant", - "duties": [ - "Research assigned prospects and companies", - "Prepare customized proposals and presentations", - "Draft follow-up emails", - "Analyze deal history and suggest strategies", - "Prepare meeting briefs" - ] - }, - "resources": { - "agents": ["company-researcher", "proposal-writer", "email-drafter"], - "mcp": [ - { "id": "crm", "tools": ["query", "update"] }, - { "id": "linkedin", "tools": ["search", "profile"] }, - { "id": "email", "tools": ["draft", "send"] } - ] - }, - "delivery": { - "type": "email", - "opts": { "to": ["sales-manager@company.com"] } + "triggers": { + "clock": { "enabled": false }, + "intervene": { + "enabled": true, + "actions": ["add_task", "adjust_goal", "pause"] } + }, + "identity": { + "role": "Sales Assistant", + "duties": [ + "Research assigned prospects and companies", + "Prepare customized proposals and presentations", + "Draft follow-up emails", + "Analyze deal history and suggest strategies", + "Prepare meeting briefs" + ] + }, + "resources": { + "agents": ["company-researcher", "proposal-writer", "email-drafter"], + "mcp": [ + { "id": "crm", "tools": ["query", "update"] }, + { "id": "linkedin", "tools": ["search", "profile"] }, + { "id": "email", "tools": ["draft", "send"] } + ] + }, + "delivery": { + "type": "email", + "opts": { "to": ["sales-manager@company.com"] } } } ``` @@ -1266,47 +1278,45 @@ Agent Continues: **Role:** Instantly process and qualify new leads, route to sales. ```json +// robot_config for Lead Processor { - "agent_id": "lead-processor", - "agent_config": { - "triggers": { - "clock": { "enabled": false }, - "event": { "enabled": true } - }, - "events": [ - { - "type": "webhook", - "source": "/webhook/leads", - "filter": { "event_types": ["lead.created"] } - }, - { - "type": "database", - "source": "crm_leads", - "filter": { "trigger": "insert" } - } - ], - "identity": { - "role": "Lead Qualification Specialist", - "duties": [ - "Instantly process new leads", - "Enrich lead data (company info, LinkedIn)", - "Score lead quality (1-100)", - "Route hot leads to sales immediately", - "Add cold leads to nurture sequence" - ] - }, - "resources": { - "agents": ["data-enricher", "lead-scorer"], - "mcp": [ - { "id": "clearbit", "tools": ["enrich"] }, - { "id": "crm", "tools": ["update", "assign"] }, - { "id": "email", "tools": ["send"] } - ] - }, - "delivery": { + "triggers": { + "clock": { "enabled": false }, + "event": { "enabled": true } + }, + "events": [ + { "type": "webhook", - "opts": { "url": "https://slack.com/webhook/sales-leads" } + "source": "/webhook/leads", + "filter": { "event_types": ["lead.created"] } + }, + { + "type": "database", + "source": "crm_leads", + "filter": { "trigger": "insert" } } + ], + "identity": { + "role": "Lead Qualification Specialist", + "duties": [ + "Instantly process new leads", + "Enrich lead data (company info, LinkedIn)", + "Score lead quality (1-100)", + "Route hot leads to sales immediately", + "Add cold leads to nurture sequence" + ] + }, + "resources": { + "agents": ["data-enricher", "lead-scorer"], + "mcp": [ + { "id": "clearbit", "tools": ["enrich"] }, + { "id": "crm", "tools": ["update", "assign"] }, + { "id": "email", "tools": ["send"] } + ] + }, + "delivery": { + "type": "webhook", + "opts": { "url": "https://slack.com/webhook/sales-leads" } } } ``` From da3a932e7128c546852e60b5f9b4b5680f3c114c Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Jan 2026 10:26:47 +0800 Subject: [PATCH 12/12] Update Autonomous Agent Design Document to Reflect Go API Changes and Execution Flow Enhancements - Introduced a new section detailing Go APIs for job management, replacing previous API references for clarity and consistency. - Updated job creation and execution handling examples to utilize the new job package methods, improving code clarity and structure. - Enhanced query examples for listing jobs, executions, and logs, providing clearer guidance on usage within the autonomous agent context. - Revised the document to align with recent changes in job management and execution processes, ensuring accurate representation of the agent's functionality. --- agent/autonomous/DESIGN.md | 102 +++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 32 deletions(-) diff --git a/agent/autonomous/DESIGN.md b/agent/autonomous/DESIGN.md index fe83660e..f722ad4e 100644 --- a/agent/autonomous/DESIGN.md +++ b/agent/autonomous/DESIGN.md @@ -681,16 +681,23 @@ Each agent = 1 Job. Each run = 1 Execution. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` -**APIs:** +**Go APIs (yao/job package):** -| Action | API | -| -------- | -------------------------------------------- | -| List | `GET /api/jobs?category_id=autonomous_robot` | -| History | `GET /api/jobs/:job_id/executions` | -| Progress | `GET /api/jobs/:job_id/executions/:id` | -| Logs | `GET /api/jobs/:job_id/executions/:id/logs` | -| Cancel | `POST /api/jobs/:job_id/stop` | -| Trigger | `POST /api/jobs/:job_id/trigger` | +| Action | API | +| ------------ | -------------------------------------------------------- | +| List Jobs | `job.ListJobs(param, page, pagesize)` | +| Get Job | `job.GetJob(jobID, param)` | +| Save Job | `job.SaveJob(j)` | +| List Execs | `job.ListExecutions(param, page, pagesize)` | +| Get Exec | `job.GetExecution(execID, param)` | +| Save Exec | `job.SaveExecution(exec)` | +| List Logs | `job.ListLogs(param, page, pagesize)` | +| Save Log | `job.SaveLog(log)` | +| Push (start) | `j.Push()` | +| Stop | `j.Stop()` | +| Destroy | `j.Destroy()` | +| Active Jobs | `job.GetActiveJobs()` | +| Query by Cat | `job.ListJobs({Wheres: [{Column: "category_id", ...}]})` | ### 7.2 Private KB @@ -808,40 +815,71 @@ type RobotState struct { } ``` -### 8.4 Execution (Uses Job System) +### 8.3 Execution (Uses Job System) No separate `autonomous_executions` table. Uses existing Job system: ```go -// On robot member create -job.Create(Job{ - ID: "robot_" + memberID, - CategoryID: "autonomous_robot", - Name: member.DisplayName, - Handler: "autonomous.Execute", - Args: map[string]interface{}{"member_id": memberID}, +// On robot member create - use Once/Cron/Daemon based on clock mode +j, _ := job.Once(job.GOROUTINE, map[string]interface{}{ + "job_id": "robot_" + memberID, + "category_id": "autonomous_robot", + "name": member.DisplayName, }) +job.SaveJob(j) -// On trigger (clock/human/event) -job.Push(jobID, ExecutionArgs{ - TriggerType: TriggerClock, // or TriggerHuman, TriggerEvent - TriggerData: data, -}) +// Add execution with config +exec := &job.Execution{ + ExecutionID: gonanoid.Must(), + JobID: j.JobID, + Status: "queued", + TriggerCategory: string(TriggerClock), // or TriggerHuman, TriggerEvent + ExecutionConfig: &job.ExecutionConfig{ + Type: job.ExecutionTypeProcess, + ProcessName: "autonomous.Execute", + ProcessArgs: []interface{}{memberID, triggerData}, + }, +} +job.SaveExecution(exec) + +// Start execution +j.Push() // Query history -executions := job.GetExecutions(jobID, limit) -logs := job.GetLogs(executionID) +param := model.QueryParam{ + Wheres: []model.QueryWhere{{Column: "job_id", Value: j.JobID}}, +} +execs, _ := job.ListExecutions(param, 1, 10) ``` -**Job APIs for monitoring:** +**Query examples:** -| Action | API | -| ------- | ------------------------------------------- | -| List | `GET /api/jobs?category=autonomous_robot` | -| Status | `GET /api/jobs/:job_id` | -| History | `GET /api/jobs/:job_id/executions` | -| Logs | `GET /api/jobs/:job_id/executions/:id/logs` | -| Cancel | `POST /api/jobs/:job_id/cancel` | +```go +// List robot jobs +param := model.QueryParam{ + Wheres: []model.QueryWhere{ + {Column: "category_id", Value: "autonomous_robot"}, + }, +} +jobs, _ := job.ListJobs(param, 1, 20) + +// Get executions for a robot +execParam := model.QueryParam{ + Wheres: []model.QueryWhere{ + {Column: "job_id", Value: "robot_" + memberID}, + }, + Orders: []model.QueryOrder{{Column: "created_at", Option: "desc"}}, +} +execs, _ := job.ListExecutions(execParam, 1, 10) + +// Get logs for an execution +logParam := model.QueryParam{ + Wheres: []model.QueryWhere{ + {Column: "execution_id", Value: execID}, + }, +} +logs, _ := job.ListLogs(logParam, 1, 100) +``` ---