|
| 1 | +## 🧶 Agent Execution Sequence |
| 2 | + |
| 3 | +The following diagram shows the complete SGR agent workflow with interruption and clarification support: |
| 4 | + |
| 5 | +```mermaid |
| 6 | +sequenceDiagram |
| 7 | + participant Client |
| 8 | + participant API as FastAPI Server |
| 9 | + participant Agent as SGR Agent |
| 10 | + participant LLM as LLM |
| 11 | + participant Tools as Research Tools |
| 12 | +
|
| 13 | + Note over Client, Tools: SGR Agent Core - Agent Workflow |
| 14 | +
|
| 15 | + Client->>API: POST /v1/chat/completions<br/>{"model": "sgr_agent", "messages": [...]} |
| 16 | +
|
| 17 | + API->>Agent: Create new SGR Agent<br/>with unique ID |
| 18 | + Note over Agent: State: INITED |
| 19 | +
|
| 20 | + Agent->>Agent: Initialize context<br/>and conversation history |
| 21 | +
|
| 22 | + loop SGR Reasoning Loop (max 6 steps) |
| 23 | + Agent->>Agent: Prepare tools based on<br/>current context limits |
| 24 | + Agent->>LLM: Structured Output Request<br/>with NextStep schema |
| 25 | +
|
| 26 | + LLM-->>API: Streaming chunks |
| 27 | + API-->>Client: SSE stream with<br/>agent_id in model field |
| 28 | +
|
| 29 | + LLM->>Agent: Parsed NextStep result |
| 30 | +
|
| 31 | + alt Tool: Clarification |
| 32 | + Note over Agent: State: WAITING_FOR_CLARIFICATION |
| 33 | + Agent->>Tools: Execute clarification tool |
| 34 | + Tools->>API: Return clarifying questions |
| 35 | + API-->>Client: Stream clarification questions |
| 36 | +
|
| 37 | + Client->>API: POST /v1/chat/completions<br/>{"model": "agent_id", "messages": [...]} |
| 38 | + API->>Agent: provide_clarification() |
| 39 | + Note over Agent: State: RESEARCHING |
| 40 | + Agent->>Agent: Add clarification to context |
| 41 | +
|
| 42 | + else Tool: GeneratePlan |
| 43 | + Agent->>Tools: Execute plan generation |
| 44 | + Tools->>Agent: Research plan created |
| 45 | +
|
| 46 | + else Tool: WebSearch |
| 47 | + Agent->>Tools: Execute web search |
| 48 | + Tools->>Tools: Tavily API call |
| 49 | + Tools->>Agent: Search results + sources |
| 50 | + Agent->>Agent: Update context with sources |
| 51 | +
|
| 52 | + else Tool: AdaptPlan |
| 53 | + Agent->>Tools: Execute plan adaptation |
| 54 | + Tools->>Agent: Updated research plan |
| 55 | +
|
| 56 | + else Tool: CreateReport |
| 57 | + Agent->>Tools: Execute report creation |
| 58 | + Tools->>Tools: Generate comprehensive<br/>report with citations |
| 59 | + Tools->>Agent: Final research report |
| 60 | +
|
| 61 | + else Tool: ReportCompletion |
| 62 | + Note over Agent: State: COMPLETED |
| 63 | + Agent->>Tools: Execute completion |
| 64 | + Tools->>Agent: Task completion status |
| 65 | + end |
| 66 | +
|
| 67 | + Agent->>Agent: Add tool result to<br/>conversation history |
| 68 | + API-->>Client: Stream tool execution result |
| 69 | +
|
| 70 | + break Task Completed |
| 71 | + Agent->>Agent: Break execution loop |
| 72 | + end |
| 73 | + end |
| 74 | +
|
| 75 | + Agent->>API: Finish streaming |
| 76 | + API-->>Client: Close SSE stream |
| 77 | +
|
| 78 | + Note over Client, Tools: Agent remains accessible<br/>via agent_id for further clarifications |
| 79 | +``` |
| 80 | + |
| 81 | +## 🤖 Schema-Guided Reasoning Capabilities: |
| 82 | + |
| 83 | +1. **🤔 Clarification** - clarifying questions when unclear |
| 84 | +2. **📋 Plan Generation** - research plan creation |
| 85 | +3. **🔍 Web Search** - internet information search |
| 86 | +4. **🔄 Plan Adaptation** - plan adaptation based on results |
| 87 | +5. **📝 Report Creation** - detailed report creation |
| 88 | +6. **✅ Final Answer** - task completion |
0 commit comments