9c191680c3f5e9e6ffc5774b5601a493e58b69ec
LangGraph CLI Agent
Overview
This repository contains a simple command‑line agent built with LangGraph and LangChain OpenAI. The agent:
- Plans a user‑supplied task into 3‑6 discrete steps.
- Executes each step sequentially, collecting results.
- 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
# 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:
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
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 de‑facto language for web development. Both languages have robust ecosystems, but their strengths differ.
Development
- Graph: The graph is defined in
agent.pyusingStateGraph. The state is aTypedDictnamedPlanningState. - 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.
Description
Languages
Python
100%