A LangGraph + Ollama coding agent usable as a library via agent.run(query)
Project description
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 varOLLAMA_MODELor"qwen2.5-coder:7b".base_url— Ollama server URL. Defaults to env varOLLAMA_BASE_URLor"http://localhost:11434".temperature— sampling temperature (default0, 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 blockinginput()prompt.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coding_agent_lib-0.1.0.tar.gz.
File metadata
- Download URL: coding_agent_lib-0.1.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51c8e795df1332dd8973f8f57edaf5e3135472fef17c2e92529393bd90be7043
|
|
| MD5 |
d2886b9398462fe647125f7ba27ebf44
|
|
| BLAKE2b-256 |
8aebac82da6e6a1a631b787af9801443a51d7377093a11c4a4d0ef61a8fb088e
|
File details
Details for the file coding_agent_lib-0.1.0-py3-none-any.whl.
File metadata
- Download URL: coding_agent_lib-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca30a7ad0e991c8e90f6d84a6627ccd00d0eb05523bbb7b3739b46e693f1259e
|
|
| MD5 |
6fd922548f2971f148c18bfecb913660
|
|
| BLAKE2b-256 |
e434e4dbf2ce27a69a2f04252c6975dcf40d227f8d3f0bb09162003385614dca
|