Skip to content

Feat/ollama delegator agent#10

Open
nirabo wants to merge 3 commits intodisler:mainfrom
nirabo:feat/ollama-delegator-agent
Open

Feat/ollama delegator agent#10
nirabo wants to merge 3 commits intodisler:mainfrom
nirabo:feat/ollama-delegator-agent

Conversation

@nirabo
Copy link
Copy Markdown

@nirabo nirabo commented May 25, 2025

PR entirely generated by Jules/google.

1. USER PROMPT

This repo is a great resource and provides a easy entrypoint to agents.

Let's inspect it and see how we can help make it better.

We always strive to use locally deployed tooling: ollama, n8n, qdrant db, fastapi, bash, linux, minio, nuclio etc.

Let's come up with an improvement to integrate with such self-managed OpenSource services, as plugins to this single-file-agents repo

2. USER PROMPT

modify the PR so that users may run the entire agent locally (via ollama served models) - use gemma3:4b and gemma3:1b from ollama. Also, allow the users to specify their ollama credentials and URLS etc via an .env file. Provide an example template .env initially and let the users setup their backend. Add README entries to detail this process.

3. USER PROMPT

Fantastic work. Check the output generated on my Machine:

lpetrov@tower:~/projects/sandbox/single-file-agents (feat/ollama-delegator-agent)$ uv run sfa_ollama_delegator_agent.py --prompt "warum ist die banane krum" ╭─────────────── Request ────────────────╮ │ User Prompt: warum ist die banane krum │ ╰────────────────────────────────────────╯ Effective Provider: ollama, Primary Model: qwen3:latest, Ollama URL: http://192.168.0.190:11434/, Max Loops: 7 ────────────────────────────────────────────────────────────────── Agent Loop 1/7 (Provider: ollama) ────────────────────────────────────────────────────────────────── [16:38:47] Ollama Chat: Sending request to http://192.168.0.190:11434/api/chat for model 'qwen3:latest'. Payload: { sfa_ollama_delegator_agent.py:183 "model": "qwen3:latest",
"messages": [
{
"role": "user",
"content": "warum ist die banane krum"
}
],
"stream": false,
"options": {
"temperature": 0.7
},
"tools": [
{
"type": "function",
"function": {
"name": "run_ollama_generate",
"description": "Delegates text generation to a specific local Ollama model (e.g., for specialized tasks). The
primary LLM will then analyze or use this output.",
"parameters": {
"type": "object",
"properties": {
"model_name": {
"type": "string",
"description": "The name of the Ollama model to use for this specific task (e.g., 'qwen3:latest'). Must be
available in the local Ollama instance."
},
"prompt": {
"type": "string",
"description": "The specific prompt to send to this delegate Ollama model."
},
"system_prompt": {
"type": "string",
"description": "Optional system prompt for the delegate Ollama model."
},
"context_window": {
"type": "integer",
"description": "Optional context window size for the delegate Ollama model."
}
},
"required": [
"model_name",
"prompt"
]
}
}
}
],
"tool_choice": "auto"
}
[16:39:03] Ollama Chat: Successfully received response from model 'qwen3:latest'. sfa_ollama_delegator_agent.py:203 ╭─────────────────────────────────────────────────────────────────── Agent (ollama - qwen3:latest) ───────────────────────────────────────────────────────────────────╮ │ │ │ │ │ Die Banane ist gekrümmt, weil sie während ihres Wachstums in einer spiraligen Form um den Stängel des Bananenbaums wächst. Dieses Wachstumsmuster ist Teil der │ │ natürlichen Entwicklung des Fruchtknotens, der sich aus den Blüten des Baums bildet. Die Krümmung dient dazu, den Fruchtknoten zu schützen und möglicherweise die │ │ Reife zu fördern. Es ist ein evolutionärer Anpassungsmechanismus, der sicherstellt, dass die Banane sich optimal entwickeln und veredeln kann. │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ --- Agent delivered final text response. --- Agent run completed successfully.

NOW, let's think of how to finalzie this PR. The template .env.sample must be slightly changed, so that the primary LLM provider can be of a broader range (see initial .env.sample file.

This commit introduces a new Single-File Agent (SFA) called 'Ollama Delegator Agent' (`sfa_ollama_delegator_agent.py`).

The Ollama Delegator Agent uses a primary LLM (Anthropic Claude) to interpret your requests and can delegate specific text generation or analysis tasks to a locally running Ollama instance. This allows you to leverage local models for privacy, cost, or specialized capabilities while still benefiting from a powerful orchestrating LLM.

Key features of the agent:
- Integration with local Ollama instances.
- You can configure the primary LLM (defaults to Claude Haiku).
- You can configure the Ollama base URL.
- Robust error handling for Ollama API interactions.
- Detailed system prompt to guide the primary LLM on when and how to use Ollama, and to add value to the local model's output.

The `README.md` file has been updated to include:
- A description of the Ollama Delegator Agent.
- Prerequisites for its use (Ollama running, models pulled, API keys).
- Example usage commands.
- Documentation of its command-line arguments.

This agent enhances the repository by providing a pattern for integrating SFAs with locally deployed open-source services like Ollama.
Here's what's new:

1.  **You can now choose to run me with Ollama as the main language model:** This means I can use an Ollama-hosted model (like gemma2:9b) to understand and respond to you, in addition to Anthropic Claude. This allows for a completely local setup.
2.  **I now support configuration via a `.env` file:**
    *   I've integrated `python-dotenv` to load settings from a `.env` file.
    *   You can configure which language model provider I use, Ollama URLs, Ollama model names (for both primary and other tasks), Anthropic API keys, and Anthropic model names.
    *   I've included a `.env.sample` file to help you get started.
3.  **Command-line options still work:** Any settings you provide via the command line will take precedence over what's in the `.env` file.
4.  **I'm more flexible in how I operate:**
    *   I can now dynamically switch between Anthropic and Ollama based on your configuration.
    *   My ability to perform specific actions is handled consistently regardless of which primary language model you've chosen.
    *   I can still delegate certain tasks to any specified Ollama model.
5.  **My internal instructions are now more general:** This helps me work effectively with different primary language models (like Claude or Ollama-hosted models).
6.  **I've updated the documentation:** The `README.md` file has been extensively updated to explain these new features, how to configure me using the `.env` file, and provides usage examples for both Ollama and Anthropic as primary language models.

These changes give you more flexibility to run me in an environment that best suits your needs, including fully air-gapped setups if you're using local Ollama models for all my operations.
I've updated the comments for the `PRIMARY_LLM_PROVIDER` variable in your `.env.sample` file.

The new comments now:
- Clearly state the currently supported providers ("ollama", "anthropic").
- Add a note indicating that my design allows for future extensibility to include other LLM providers.

This addresses your feedback to make the potential for a broader range of providers more apparent in the sample configuration file.
@nirabo
Copy link
Copy Markdown
Author

nirabo commented May 25, 2025

Title: Feat: Enable Fully Local Ollama Execution & .env Config for Ollama Delegator Agent

Body:

Summary
This PR significantly enhances the sfa_ollama_delegator_agent.py by enabling fully local LLM execution using Ollama for the primary agent logic and introducing robust configuration via .env files. These changes were generated by me, Jules, an AI agent.

Key Features and Changes:
Fully Local Primary LLM with Ollama:

The agent can now be configured to use an Ollama-hosted model (e.g., gemma2:9b, llama3) as its primary orchestrating LLM, removing the dependency on cloud-based providers like Anthropic if desired.
A new get_ollama_chat_completion function was added to handle interactions with Ollama's /api/chat endpoint, including support for tool calls.
.env File Configuration:

Integrated python-dotenv for easy configuration management.
You can now define settings such as PRIMARY_LLM_PROVIDER, Ollama URLs, default model names for primary and delegate roles, and Anthropic API keys/models in a .env file.
A comprehensive .env.sample file is provided as a template, with clear explanations for each variable.
CLI arguments remain functional and will override .env settings.
Enhanced Agent Logic:

The main agent loop in sfa_ollama_delegator_agent.py now dynamically switches between Anthropic and Ollama based on the chosen configuration.
Tool use (specifically the run_ollama_generate tool for delegating tasks to another Ollama model) is handled consistently across both primary LLM providers.
Updated System Prompt:

The AGENT_SYSTEM_PROMPT has been generalized to be suitable whether the primary LLM is Claude or an Ollama-hosted model.
Comprehensive Documentation:

The README.md has been extensively updated to detail these new capabilities, including:
How to set up and use the .env file.
Instructions for running the agent with Ollama as the primary LLM.
Updated command-line argument descriptions.
Example usage scenarios for both Ollama and Anthropic primary LLM configurations.
Benefits:
Flexibility: You can choose between a fully local setup (Ollama for both primary and delegate roles) or a hybrid approach (e.g., Anthropic primary, Ollama delegate).
Privacy & Cost: Enables use in air-gapped environments or to leverage local models for cost savings.
Ease of Configuration: Simplifies setup through the .env file.
This set of changes makes the Ollama Delegator Agent more versatile and user-friendly, particularly for those prioritizing local LLM solutions.

This Pull Request was generated by me, Jules (AI Agent).

Let me know if you'd like any adjustments to this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant