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.
This commit is contained in:
Max 2026-01-13 10:26:47 +08:00
parent d7d6f1b77b
commit da3a932e71

View file

@ -681,16 +681,23 @@ Each agent = 1 Job. Each run = 1 Execution.
└─────────────────────────────────────────────────────────────────┘ └─────────────────────────────────────────────────────────────────┘
``` ```
**APIs:** **Go APIs (yao/job package):**
| Action | API | | Action | API |
| -------- | -------------------------------------------- | | ------------ | -------------------------------------------------------- |
| List | `GET /api/jobs?category_id=autonomous_robot` | | List Jobs | `job.ListJobs(param, page, pagesize)` |
| History | `GET /api/jobs/:job_id/executions` | | Get Job | `job.GetJob(jobID, param)` |
| Progress | `GET /api/jobs/:job_id/executions/:id` | | Save Job | `job.SaveJob(j)` |
| Logs | `GET /api/jobs/:job_id/executions/:id/logs` | | List Execs | `job.ListExecutions(param, page, pagesize)` |
| Cancel | `POST /api/jobs/:job_id/stop` | | Get Exec | `job.GetExecution(execID, param)` |
| Trigger | `POST /api/jobs/:job_id/trigger` | | 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 ### 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: No separate `autonomous_executions` table. Uses existing Job system:
```go ```go
// On robot member create // On robot member create - use Once/Cron/Daemon based on clock mode
job.Create(Job{ j, _ := job.Once(job.GOROUTINE, map[string]interface{}{
ID: "robot_" + memberID, "job_id": "robot_" + memberID,
CategoryID: "autonomous_robot", "category_id": "autonomous_robot",
Name: member.DisplayName, "name": member.DisplayName,
Handler: "autonomous.Execute",
Args: map[string]interface{}{"member_id": memberID},
}) })
job.SaveJob(j)
// On trigger (clock/human/event) // Add execution with config
job.Push(jobID, ExecutionArgs{ exec := &job.Execution{
TriggerType: TriggerClock, // or TriggerHuman, TriggerEvent ExecutionID: gonanoid.Must(),
TriggerData: data, 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 // Query history
executions := job.GetExecutions(jobID, limit) param := model.QueryParam{
logs := job.GetLogs(executionID) Wheres: []model.QueryWhere{{Column: "job_id", Value: j.JobID}},
}
execs, _ := job.ListExecutions(param, 1, 10)
``` ```
**Job APIs for monitoring:** **Query examples:**
| Action | API | ```go
| ------- | ------------------------------------------- | // List robot jobs
| List | `GET /api/jobs?category=autonomous_robot` | param := model.QueryParam{
| Status | `GET /api/jobs/:job_id` | Wheres: []model.QueryWhere{
| History | `GET /api/jobs/:job_id/executions` | {Column: "category_id", Value: "autonomous_robot"},
| Logs | `GET /api/jobs/:job_id/executions/:id/logs` | },
| Cancel | `POST /api/jobs/:job_id/cancel` | }
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)
```
--- ---