A small example project demonstrating a self-improving agent that uses a local Ollama LLM to generate and refine Monty-compatible Python snippets and execute them via pydantic-monty.
- Prerequisites: Python 3.12+, Ollama running locally and accessible to the
ollamaPython client. - Install dependencies (editable install recommended for development):
python -m pip install --upgrade pip
python -m pip install -e .[dev]- Create a sample config (creates
config/agent_config.toml):
python examples/create_sample_config.pyEdit config/agent_config.toml to set model, max_attempts, and logging settings.
Run the example agent from the project root (after creating a config):
python -m src.monty_ollama_agentOr import and instantiate the agent in your own script:
from src.monty_ollama_agent import SelfImprovingAgent
agent = SelfImprovingAgent(config_path="config/agent_config.toml")
result = agent.run("your task description", {"a": 1, "b": 2}) # This is where the problem to be solve and inputs defined Run the test suite with pytest. If you installed the dev extras above you can run directly; otherwise set PYTHONPATH so tests can import src:
# If pytest is installed in the venv
pytest -q
# Or, with PYTHONPATH set (works if pytest is in the venv but package not installed)
PYTHONPATH=$(pwd) .venv/bin/pytest -qsrc/monty_ollama_agent.py— main agent implementationexamples/create_sample_config.py— utility to create a starterconfig/agent_config.tomlconfig/agent_config.toml— configuration for model, prompts, and loggingtests/— pytest unit tests (run withpytest)
- The project requires Python >=3.12 (see
pyproject.toml). - The module no longer auto-creates a config on import — use
examples/create_sample_config.pyto create a starter file. - The agent executes generated code via
pydantic-monty; treat generated code as untrusted and run it in a controlled environment.
See the repository LICENSE file.