Metadata-Version: 2.4
Name: coding-agent-lib
Version: 0.1.0
Summary: A LangGraph + Ollama coding agent usable as a library via agent.run(query)
Author-email: Your Name <you@example.com>
License: MIT License
        
        Copyright (c) 2026 Your Name
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/your-username/coding-agent-lib
Project-URL: Repository, https://github.com/your-username/coding-agent-lib
Project-URL: Issues, https://github.com/your-username/coding-agent-lib/issues
Keywords: ai,agent,langgraph,ollama,llm,code-generation,coding-agent
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Code Generators
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: langgraph
Requires-Dist: langchain-ollama
Requires-Dist: langchain-core
Dynamic: license-file

# 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

```bash
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.:

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

## Usage

```python
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.
