Principle:Ollama Ollama AgentArchitecture
| Knowledge Sources | |
|---|---|
| Domains | Agent, Tool Use |
| Last Updated | 2025-02-15 00:00 GMT |
Overview
The Agent Architecture provides an agentic tool-use framework within Ollama that enables LLMs to autonomously invoke tools in a loop, with an approval workflow that gives users control over which tool executions are permitted before they run.
Core Concepts
Agentic Loop
The agentic architecture implements a generate-act-observe loop. The model generates a response that may include tool calls, the system executes approved tool calls and collects results, and the results are fed back to the model as new context for the next generation step. This loop continues until the model produces a response without tool calls (indicating task completion) or a maximum iteration limit is reached.
Approval Workflow
Unlike simple tool calling where all invocations are automatically executed, the agent architecture introduces an approval layer. Before a tool call is executed, the system presents it to the user (or an automated policy) for approval. This is critical for safety in agentic scenarios where tool calls may have side effects such as file system modifications, API calls, or code execution. The approval system supports allow, deny, and allow-all-of-type responses.
Platform-Specific Approval
The approval mechanism adapts to the host platform. On Unix systems, the approval interface uses terminal-based interactive prompts. On Windows, the implementation adapts to the Windows console API. This platform abstraction ensures the approval workflow provides a consistent user experience across operating systems while leveraging platform-native input mechanisms.
Tool Execution Sandbox
Within the agentic framework, tool execution can be sandboxed to limit the blast radius of potentially harmful operations. The framework provides mechanisms to restrict tool capabilities, validate arguments before execution, and capture output for review. This defense-in-depth approach complements the approval workflow by providing guardrails even for approved operations.
Session State Management
The agent maintains session state across loop iterations, tracking the conversation history, tool call results, and accumulated context. This state management ensures that each iteration of the generate-act-observe loop has access to the full history of prior interactions, enabling the model to make informed decisions about subsequent tool invocations.
Implementation Notes
The agent approval system is implemented in x/agent/approval.go with platform-specific implementations in x/agent/approval_unix.go and x/agent/approval_windows.go. The agentic loop is orchestrated by the agent command infrastructure under x/agent/. The approval workflow integrates with the tool calling pipeline, intercepting tool call objects before execution and gating them through the user approval interface.