2026-06-02 14:52:10 +00:00
2026-06-02 14:52:10 +00:00
2026-06-02 14:51:58 +00:00

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

# 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 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.

S
Description
Auto repo for task 6a1864fd8a94f887e50d4706
Readme 28 KiB
Languages
Python 100%