This commit is contained in:
2026-07-31 11:41:53 +07:00
parent c9a7661e93
commit 7876ff21eb
8 changed files with 1671 additions and 2168 deletions
+34 -20
View File
@@ -37,7 +37,7 @@ agent = Agent(Dict(
prompt(agent, "Hello!")
# Wait for completion
wait_for_idle(agent)
waitForIdle(agent)
```
### Understanding the Flow
@@ -83,6 +83,12 @@ User Code
- `steer()` - Queue message for next turn
- `followUp()` - Queue message after stop
- `subscribe()` - Listen to events
- `waitForIdle()` - Wait for agent to finish processing
- `reset!()` - Clear transcript state and queued messages
- `clearAllQueues()` - Remove all queued steering and follow-up messages
- `hasQueuedMessages()` - Check if queues have pending messages
- `abort()` - Abort the current run
- `get_state()` - Get the current agent state
### AgentLoop
@@ -113,9 +119,14 @@ User Code
**Key methods**:
- `appendMessage()` - Add message
- `appendCompaction()` - Compress history
- `appendCompaction()` - Compress history with summary
- `moveTo()` - Navigate branches
- `buildSessionContext()` - Build context for LLM
- `buildContext()` - Build context for LLM
- `getBranch()` - Get branch entries
- `getSessionStats()` - Get session statistics
- `appendThinkingLevelChange()` - Record thinking level change
- `appendModelChange()` - Record model change
- `appendActiveToolsChange()` - Record active tools change
### Tools
@@ -193,20 +204,23 @@ Message (for LLM API)
├── is_error::Bool
└── timestamp::Timestamp
AgentMessage (internal, extends Message)
AgentMessage (internal, abstract type)
├── UserMessage (same as above)
├── AssistantMessage (same as above)
├── ToolResultMessage (same as above)
├── ToolResultMessage (same as above, plus: role, added_tool_names)
├── BashExecutionMessage (custom)
│ ├── role, command, output, exit_code
│ ├── cancelled, truncated, exclude_from_context
│ └── timestamp
│ ├── cancelled, truncated, full_output_path, timestamp
│ └── exclude_from_context
├── CompactionSummaryMessage (custom)
│ ├── summary, tokens_before, timestamp
│ ├── role, summary, tokens_before, timestamp
│ └── converted to UserMessage for LLM
── BranchSummaryMessage (custom)
├── summary, from_id, timestamp
└── converted to UserMessage for LLM
── BranchSummaryMessage (custom)
├── role, summary, from_id, timestamp
└── converted to UserMessage for LLM
└── CustomMessage (custom, extends AgentMessage)
├── message::AgentMessage
└── custom_type::String
```
### Complete Conversation Flow
@@ -427,7 +441,7 @@ appendMessage(session, user_message)
appendMessage(session, assistant_message)
# Build context from session
context = buildSessionContext(session)
context = buildContext(session)
```
### Pattern 2: Long Conversations
@@ -451,7 +465,7 @@ end
session.moveTo(branch_point_id)
# Create new branch
appendBranchSummary(session, "Exploring alternative approach")
moveTo(session, branch_point_id, summary=["summary" => "Exploring alternative approach"])
appendMessage(session, new_user_message)
```
@@ -460,13 +474,13 @@ appendMessage(session, new_user_message)
```julia
# Create custom tool
custom_tool = AgentTool(
"custom",
"custom",
"Does custom thing",
...,
execute_function,
nothing,
EXECUTION_PARALLEL,
"custom", # name
"Custom", # label
"Does custom thing", # description
parameters, # parameter schema
execute_function, # execute
nothing, # prepare_arguments (optional)
EXECUTION_PARALLEL, # execution_mode
)
# Add to agent