wip docs
This commit is contained in:
@@ -44,14 +44,15 @@ The communication model is unified under ai_client.py, which normalizes the Gemi
|
||||
|
||||
The loop is defined as follows:
|
||||
|
||||
1. **Prompt Injection:** The aggregated Markdown context and system prompt are injected. (Gemini injects this directly into system_instruction at chat instantiation to prevent history bloat; Anthropic chunks this into cache_control: ephemeral blocks).
|
||||
2. **Execution Loop:** A MAX_TOOL_ROUNDS (default 10) bounded loop begins.
|
||||
1. **Prompt Injection:** The aggregated Markdown context and system prompt are injected. For Gemini, the system_instruction and tools are stored in an explicit cache via `client.caches.create()` with a 1-hour TTL; if cache creation fails (under minimum token threshold), it falls back to inline system_instruction. When context changes mid-session, the old cache is deleted and a new one is created. For Anthropic, the system prompt + context are sent as `system=` blocks with `cache_control: ephemeral` on the last chunk, and tools carry `cache_control: ephemeral` on the last tool definition.
|
||||
2. **Execution Loop:** A MAX_TOOL_ROUNDS (default 10) bounded loop begins. The tools list for Anthropic is built once per session and reused.
|
||||
3. The AI provider is polled.
|
||||
4. If the provider's stop_reason is ool_use:
|
||||
4. If the provider's stop_reason is tool_use:
|
||||
1. The loop parses the requested tool (either a read-only MCP tool or the destructive PowerShell tool).
|
||||
2. If PowerShell, it dispatches a blocking event to the Main Thread (see *On Tool Execution & Concurrency*).
|
||||
3. Once the result is retrieved, the loop executes a **Dynamic Refresh** (_reread_file_items). Any files currently tracked by the project are pulled from the disk fresh.
|
||||
4. The tool result, appended with the fresh [FILES UPDATED] block, is sent back to the provider.
|
||||
3. Once the last tool result in the batch is retrieved, the loop executes a **Dynamic Refresh** (`_reread_file_items`). Any files currently tracked by the project are pulled from disk fresh. The `file_items` variable is reassigned so subsequent tool rounds see the updated content.
|
||||
4. For Anthropic: the refreshed file contents are appended as a text block to the tool_results user message. For Gemini: the refreshed contents are appended to the last function response's output string. In both cases, the block is prefixed with `[FILES UPDATED]` / `[SYSTEM: FILES UPDATED]`.
|
||||
5. On subsequent rounds, stale file-refresh blocks from previous turns are stripped from history to prevent token accumulation. For Gemini, old tool outputs exceeding `_history_trunc_limit` characters are also truncated.
|
||||
5. Once the model outputs standard text, the loop terminates and yields the string back to the GUI callback.
|
||||
|
||||
### On Tool Execution & Concurrency
|
||||
|
||||
Reference in New Issue
Block a user