Skip to main content

Socratic AI integration library for LangGraph - framework-agnostic agents

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Socrates AI LangGraph Integration

Framework-agnostic Socratic AI agent integration for LangGraph

This library provides seamless integration between Socrates AI components and LangGraph, enabling you to build sophisticated multi-agent workflows with Socratic method guidance, knowledge retrieval, and unified event management.

Features

🤖 LangGraph Integration - Build workflows with Socratic agents as LangGraph nodes 📚 Knowledge Retrieval - Integrated RAG capabilities (optional) 🎓 Socratic Guidance - Ask better questions, not just provide answers ⚡ Framework Agnostic - Swap LangGraph for other orchestrators easily 🔄 Event System - Unified event handling across all agents 💾 State Management - Pydantic-based state with type safety

Installation

# Core integration
pip install socrates-ai-langraph

# With agent support
pip install "socrates-ai-langraph[agents]"

# With RAG support
pip install "socrates-ai-langraph[rag]"

# Everything
pip install "socrates-ai-langraph[full]"

Quick Start

from langgraph.graph import StateGraph, START, END
from socrates_ai_langraph import create_socrates_langgraph_workflow, AgentState

# Create workflow
workflow = create_socrates_langgraph_workflow()
app = workflow.compile()

# Run
initial_state = AgentState(input="Help me design a REST API")
result = app.invoke(initial_state)

print(result.messages)
print(result.results)

Architecture

LangGraph StateGraph
    ↓
├─ analyze_node         (uses CodeAnalysisAgent)
├─ retrieve_node        (uses KnowledgeRetrievalAgent)
├─ generate_node        (uses CodeGenerationAgent)
└─ synthesize_node      (aggregates results)
    ↓
Socrates Components:
├─ SocraticConfig       (unified configuration)
├─ EventEmitter         (unified events)
└─ Socratic Libraries (optional):
   ├─ socratic-agents
   ├─ socratic-rag
   └─ socratic-learning

API Reference

State Classes

AgentState(BaseModel)

from socrates_ai_langraph import AgentState

state = AgentState(
    input="Your task here",
    messages=["Message 1", "Message 2"],
    results={"key": "value"},
    errors=[]
)

Workflow Creation

create_socrates_langgraph_workflow(config: Optional[SocratesConfig] = None) -> StateGraph

Create a pre-configured LangGraph workflow with Socratic agents.

from socrates_ai_langraph import create_socrates_langgraph_workflow

workflow = create_socrates_langgraph_workflow()
app = workflow.compile()
result = app.invoke(initial_state)

Agent Classes

CodeAnalysisAgent

Analyzes code for complexity, issues, and improvements.

from socrates_ai_langraph import CodeAnalysisAgent

agent = CodeAnalysisAgent()
result = agent.analyze("def example(): pass")
# Returns: {"complexity": "low", "issues": [], "suggestions": [...]}

CodeGenerationAgent

Generates code based on prompts.

from socrates_ai_langraph import CodeGenerationAgent

agent = CodeGenerationAgent()
code = agent.generate("Create a Python function for data validation")

KnowledgeRetrievalAgent

Retrieves relevant knowledge (requires socratic-rag).

from socrates_ai_langraph import KnowledgeRetrievalAgent

agent = KnowledgeRetrievalAgent()
docs = agent.retrieve("How to implement authentication?")

Configuration

Environment Variables

# Required for LLM features
export ANTHROPIC_API_KEY="sk-ant-..."

# Optional
export SOCRATIC_MODEL="claude-opus-4-5"
export SOCRATIC_TEMPERATURE="0.7"

Programmatic Configuration

from socratic_core import SocratesConfig
from socrates_ai_langraph import create_socrates_langgraph_workflow

config = SocratesConfig(
    model="claude-opus-4-5",
    temperature=0.7
)

workflow = create_socrates_langgraph_workflow(config)

Advanced Usage

Custom Workflow

from langgraph.graph import StateGraph, START, END
from socrates_ai_langraph import AgentState, CodeAnalysisAgent

# Create custom workflow
workflow = StateGraph(AgentState)

# Add your nodes
def my_node(state: AgentState) -> AgentState:
    analyzer = CodeAnalysisAgent()
    state.results["analysis"] = analyzer.analyze(state.input)
    return state

workflow.add_node("analyze", my_node)
workflow.add_edge(START, "analyze")
workflow.add_edge("analyze", END)

# Compile and run
app = workflow.compile()
result = app.invoke(AgentState(input="def example(): pass"))

Event Listening

from socrates_core import EventType
from socrates_ai_langraph import create_socrates_langgraph_workflow, get_config

config = get_config()
workflow = create_socrates_langgraph_workflow(config)

# Listen to events
@config.emitter.on(EventType.AGENT_START)
def on_agent_start(data):
    print(f"Agent starting: {data}")

@config.emitter.on(EventType.AGENT_COMPLETE)
def on_agent_complete(data):
    print(f"Agent complete: {data}")

# Run workflow
app = workflow.compile()
result = app.invoke(initial_state)

Examples

Example 1: Code Review Workflow

from socrates_ai_langraph import create_socrates_langgraph_workflow, AgentState

# Create workflow
workflow = create_socrates_langgraph_workflow()
app = workflow.compile()

# Review code
code = """
def process_data(data):
    result = []
    for item in data:
        result.append(item * 2)
    return result
"""

state = AgentState(input=code)
result = app.invoke(state)

print("Analysis:", result.results.get("analysis"))
print("Suggestions:", result.messages)

Example 2: Generate and Improve

from socrates_ai_langraph import CodeGenerationAgent, CodeAnalysisAgent, AgentState

# Generate code
generator = CodeGenerationAgent()
code = generator.generate("Create a fibonacci function")

# Analyze it
analyzer = CodeAnalysisAgent()
analysis = analyzer.analyze(code)

# Improve based on feedback
state = AgentState(
    input=f"Improve this code based on: {analysis['suggestions']}",
    results={"original_code": code, "analysis": analysis}
)

Comparison with Other Frameworks

Feature LangGraph Openclaw CrewAI AutoGen
Socratic Method ✅ Via socrates-ai-langraph ✅ Built-in
RAG Support ✅ Optional ✅ Built-in
State Management ✅ Pydantic ⚠️ Custom ⚠️ Custom
Async Support ✅ Full ✅ Full ✅ Full ⚠️ Limited
Framework Agnostic ✅ Yes ❌ No ❌ No ❌ No
Type Safe ✅ Yes ⚠️ Partial ❌ No ❌ No

Migration

From langgraph-socrates (if exists)

# Old import
from langgraph_socrates import create_workflow

# New import (if different)
from socrates_ai_langraph import create_socrates_langgraph_workflow

From Direct LangGraph (without Socratic)

# Before: Custom agent implementation
class MyAgent:
    def run(self, input_data):
        # Custom implementation
        pass

# After: Use built-in Socratic agents
from socrates_ai_langraph import CodeAnalysisAgent
agent = CodeAnalysisAgent()
result = agent.analyze(input_data)

Testing

# Run all tests
pytest

# With coverage
pytest --cov=socrates_ai_langraph

# Specific test
pytest tests/test_agents.py -v

Troubleshooting

Import Errors

# Error: ModuleNotFoundError: No module named 'langgraph'
# Solution:
pip install langgraph

# Error: ModuleNotFoundError: No module named 'socratic_core'
# Solution:
pip install socratic-core

Agent Not Initialized

# Error: Agent has no attribute 'run'
# Solution: Make sure to initialize config first
from socrates_ai_langraph import create_socrates_langgraph_workflow
workflow = create_socrates_langgraph_workflow()

State Serialization

# Use Pydantic models for all state
from socrates_ai_langraph import AgentState

# ✅ Good
state = AgentState(input="...", results={"key": "value"})

# ❌ Bad
state = {"input": "...", "results": {"key": "value"}}

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Write tests
  4. Submit a pull request

See CONTRIBUTING.md for details.

Support

License

MIT License - see LICENSE file

Acknowledgments

Built with:


Made with ❤️ for developers who believe in learning through questions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

socrates_ai_langraph-0.1.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

socrates_ai_langraph-0.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file socrates_ai_langraph-0.1.0.tar.gz.

File metadata

  • Download URL: socrates_ai_langraph-0.1.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for socrates_ai_langraph-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ea003557f6e0536188e555c1b6a996bc00d09f33561dcd842e56439607d600c5
MD5 ca97fb6dbfcf02cc35c39303f45f7041
BLAKE2b-256 3c34f76c6bca87c3a1df7e23b655cf29f0b5476f62a7678c5645c27a8a563695

See more details on using hashes here.

File details

Details for the file socrates_ai_langraph-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for socrates_ai_langraph-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69e108200405e8b42e8132e0ccfe323c06d10c251e79250d655bc07c47968a8e
MD5 2a2d423718ab105a7007cf623153345e
BLAKE2b-256 a5afdaaed448eebe7f9ae0ea8c335951b01d156196719556635bca66b7795224

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page