Files
task_6a1864fd8a94f887e50d47…/README.md
T
2026-06-02 14:51:58 +00:00

69 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LangGraph CLI Agent
## Overview
This repository contains a simple commandline agent built with **LangGraph** and **LangChain OpenAI**. The agent:
1. **Plans** a usersupplied task into 36 discrete steps.
2. **Executes** each step sequentially, collecting results.
3. **Summarises** the outcome after all steps are finished.
The agent runs locally and can use either an OpenAI API key or a local Ollama model.
## Installation
```bash
# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
# Install dependencies
pip install -r requirements.txt
```
The `requirements.txt` file contains:
```text
langgraph>=1.0.0
langchain-openai>=0.2.0
langchain-ollama>=0.1.0
```
## Configuration
The agent automatically chooses an LLM provider:
| Environment Variable | Meaning | Default |
|----------------------|---------|---------|
| `OPENAI_API_KEY` | OpenAI API key | *None* |
| `CHAT_MODEL` | Model name for local Ollama | `llama3` |
| `OLLAMA_BASE_URL` | Base URL for local Ollama | `http://localhost:11434/v1` |
If `OPENAI_API_KEY` is set, the agent uses the OpenAI endpoint. Otherwise it falls back to the local Ollama model.
## Usage
```bash
python agent.py "Compare Python and JavaScript"
```
Typical output:
```
===== PLAN =====
1. Compare the syntax of Python and JavaScript.
2. Discuss performance considerations.
3. Evaluate ecosystem support.
4. Summarise key differences.
===== RESULTS =====
[Step 1] Python uses indentation for blocks, whereas JavaScript uses braces.
[Step 2] JavaScript is generally faster in the browser, but Python excels in data science.
[Step 3] Python has a richer scientific stack; JavaScript dominates web development.
[Step 4] Python is best for backend and data work; JavaScript is essential for frontend.
===== SUMMARY =====
Python offers strong support for scientific computing and backend tasks, while JavaScript remains the defacto language for web development. Both languages have robust ecosystems, but their strengths differ.
```
## Development
- **Graph**: The graph is defined in `agent.py` using `StateGraph`. The state is a `TypedDict` named `PlanningState`.
- **Error handling**: All LLM calls are wrapped in try/except blocks. Parsing errors raise descriptive exceptions.
- **Testing**: The project includes minimal unit tests for plan parsing and integration tests that run the graph on a sample task.
Feel free to extend the graph with more sophisticated nodes or to plug in different LLMs.