Skip to main content

coding_agent_lib

A small Python library wrapping a LangGraph + Ollama coding agent. Instead of the original interactive input() loop, you import it and call agent.run(query) directly from your own code.

Install

pip install -e . --break-system-packages

This pulls in langgraph, langchain-ollama, and langchain-core.

You also need a running Ollama server with a model pulled locally, e.g.:

ollama pull qwen2.5-coder:7b
ollama serve

Usage

from coding_agent_lib import CodingAgent

agent = CodingAgent(model="qwen2.5-coder:7b")  # base_url defaults to localhost:11434

# Generate new code -- the agent infers intent, task, and file path from
# your natural-language query.
result = agent.run(
    "generate code for finding factorial of a number and save it to factorial.py"
)

if result.success:
    print("Written to:", result.file_path)
    print(result.code)
else:
    print("Error:", result.error)

# Debug an existing file
result = agent.run("debug factorial.py, it crashes on negative input")

CodingAgent(model=None, base_url=None, temperature=0.0, workdir=None)

  • model — Ollama model name. Defaults to env var OLLAMA_MODEL or "qwen2.5-coder:7b".
  • base_url — Ollama server URL. Defaults to env var OLLAMA_BASE_URL or "http://localhost:11434".
  • temperature — sampling temperature (default 0, deterministic).
  • workdir — if set, relative file paths extracted from queries are resolved against this directory instead of the current working directory.

agent.run(query: str) -> AgentResult

Runs a single request end-to-end (parse → generate/debug → save to disk) and returns an AgentResult:

Field Type Description
success bool True if no error occurred
query str The original query you passed in
intent "generate" | "debug" | None What the agent decided to do
task str | None Extracted coding task / debug instructions
file_path str | None Resolved path the agent wrote to
code str | None Final code written to the file
original_code str | None Pre-fix code (debug mode only)
error str | None Error message if success is False

Notes

  • The agent uses the LLM itself (not regex/keyword matching) to figure out intent, task, and file path from free-form queries.
  • "debug" mode reads the existing file, asks the LLM to fix it, and overwrites the file with the corrected version.
  • Each call to run() is independent/stateless; call it repeatedly (in a loop, a web handler, a CLI, etc.) instead of using the old blocking input() prompt.

Release files for coding-agent-lib 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coding-agent-lib 0.1.0
File Size Uploaded
coding_agent_lib-0.1.0.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for coding-agent-lib 0.1.0
File Interpreter ABI Platform
coding_agent_lib-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / coding_agent_lib-0.1.0.tar.gz

Download URL coding_agent_lib-0.1.0.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
51c8e795df1332dd8973f8f57edaf5e3135472fef17c2e92529393bd90be7043
BLAKE2b-256 checksum
How to use checksums
8aebac82da6e6a1a631b787af9801443a51d7377093a11c4a4d0ef61a8fb088e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / coding_agent_lib-0.1.0-py3-none-any.whl

Download URL coding_agent_lib-0.1.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca30a7ad0e991c8e90f6d84a6627ccd00d0eb05523bbb7b3739b46e693f1259e
BLAKE2b-256 checksum
How to use checksums
e434e4dbf2ce27a69a2f04252c6975dcf40d227f8d3f0bb09162003385614dca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page