jaf-py


Namejaf-py JSON
Version 2.2.0 PyPI version JSON
download
home_pageNone
SummaryA purely functional agent framework with immutable state and composable tools - Python implementation
upload_time2025-08-28 17:15:14
maintainerJAF Contributors
docs_urlNone
authorJAF Contributors
requires_python>=3.10
licenseNone
keywords ai agents functional python llm mcp model-context-protocol agent-framework functional-programming
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # JAF (Juspay Agent Framework) - Python Implementation

<!-- ![JAF Banner](docs/cover.png) -->

[![Version](https://img.shields.io/badge/version-2.0.0-blue.svg)](https://github.com/xynehq/jaf-py)
[![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)
[![Docs](https://img.shields.io/badge/Docs-Live-brightgreen)](https://xynehq.github.io/jaf-py/)

A purely functional agent framework with immutable state and composable tools, professionally converted from TypeScript to Python. JAF enables building production-ready AI agent systems with built-in security, observability, and error handling.

**๐ŸŽฏ Production Ready**: Complete feature parity with TypeScript version, comprehensive test suite, and production deployment support.

## ๐Ÿ“š **[Read the Full Documentation](https://xynehq.github.io/jaf-py/)**

**[๐Ÿš€ Get Started โ†’](https://xynehq.github.io/jaf-py/getting-started/)** | **[๐Ÿ“– API Reference โ†’](https://xynehq.github.io/jaf-py/api-reference/)** | **[๐ŸŽฎ Examples โ†’](https://xynehq.github.io/jaf-py/examples/)**

## โœจ Key Features

### ๐Ÿ—๏ธ **Complete TypeScript Conversion**
- โœ… **Full Feature Parity**: All TypeScript functionality converted to Python
- โœ… **Type Safety**: Pydantic models with runtime validation
- โœ… **Immutable State**: Functional programming principles preserved
- โœ… **Tool Integration**: Complete tool calling and execution system

### ๐Ÿš€ **Production Ready Server**
- โœ… **FastAPI Server**: High-performance async HTTP API
- โœ… **Auto Documentation**: Interactive API docs at `/docs`
- โœ… **Health Monitoring**: Built-in health checks and metrics
- โœ… **CORS Support**: Ready for browser integration

### ๐Ÿ”Œ **Model Context Protocol (MCP)**
- โœ… **MCP Client**: Full MCP specification support
- โœ… **Stdio & SSE**: Multiple transport protocols
- โœ… **Tool Integration**: Seamless MCP tool integration
- โœ… **Auto Discovery**: Dynamic tool loading from MCP servers

### ๐Ÿ›ก๏ธ **Enterprise Security**
- โœ… **Input Guardrails**: Content filtering and validation
- โœ… **Output Guardrails**: Response sanitization
- โœ… **Permission System**: Role-based access control
- โœ… **Audit Logging**: Complete interaction tracing

### ๐Ÿ“Š **Observability & Monitoring**
- โœ… **Real-time Tracing**: Event-driven observability
- โœ… **Structured Logging**: JSON-formatted logs
- โœ… **Error Handling**: Comprehensive error types and recovery
- โœ… **Performance Metrics**: Built-in timing and counters

### ๐Ÿ”ง **Developer Experience**
- โœ… **CLI Tools**: Project initialization and management
- โœ… **Hot Reload**: Development server with auto-reload
- โœ… **Type Hints**: Full mypy compatibility
- โœ… **Rich Examples**: RAG, multi-agent, and server demos
- โœ… **Visual Architecture**: Graphviz-powered agent and tool diagrams

## ๐ŸŽฏ Core Philosophy

- **Immutability**: All core data structures are deeply immutable
- **Pure Functions**: Core logic expressed as pure, predictable functions
- **Effects at the Edge**: Side effects isolated in Provider modules
- **Composition over Configuration**: Build complex behavior by composing simple functions
- **Type-Safe by Design**: Leverages Python's type system with Pydantic for runtime safety

## ๐Ÿš€ Quick Start

### Installation

```bash
# Install from GitHub (development version)
pip install git+https://github.com/xynehq/jaf-py.git

# Or install with all optional dependencies
pip install "jaf-py[all] @ git+https://github.com/xynehq/jaf-py.git"

# Install specific feature sets
pip install "jaf-py[server] @ git+https://github.com/xynehq/jaf-py.git"        # FastAPI server support
pip install "jaf-py[memory] @ git+https://github.com/xynehq/jaf-py.git"        # Redis/PostgreSQL memory providers
pip install "jaf-py[visualization] @ git+https://github.com/xynehq/jaf-py.git" # Graphviz visualization tools
pip install "jaf-py[dev] @ git+https://github.com/xynehq/jaf-py.git"           # Development tools
```

### CLI Usage

JAF includes a powerful CLI for project management:

```bash
# Initialize a new JAF project
jaf init my-agent-project

# Run the development server
jaf server --host 0.0.0.0 --port 8000

# Show version and help
jaf version
jaf --help
```

### Development Setup

```bash
git clone https://github.com/xynehq/jaf-py
cd jaf-py
pip install -e ".[dev]"

# Run tests
pytest

# Type checking and linting
mypy jaf/
ruff check jaf/
black jaf/

# Documentation
pip install -r requirements-docs.txt
./docs.sh serve  # Start documentation server
./docs.sh deploy # Deploy to GitHub Pages
```

## ๐Ÿ“– Documentation

### ๐ŸŒ **[Official Documentation Website](https://xynehq.github.io/jaf-py/)**

The complete, searchable documentation is available at **[xynehq.github.io/jaf-py](https://xynehq.github.io/jaf-py/)** with:

- โœ… **Interactive navigation** with search and filtering
- โœ… **Dark/light mode** with automatic system preference detection  
- โœ… **Mobile-responsive design** for documentation on any device
- โœ… **Live code examples** with syntax highlighting
- โœ… **API reference** with auto-generated documentation
- โœ… **Always up-to-date** with automatic deployments

### ๐Ÿ“ **Local Documentation**

For offline access, documentation is also available in the [`docs/`](docs/) directory:

- **[๐Ÿ“š Documentation Hub](docs/README.md)** - Your starting point for all documentation
- **[๐Ÿš€ Getting Started](docs/getting-started.md)** - Installation and first agent tutorial
- **[๐Ÿ—๏ธ Core Concepts](docs/core-concepts.md)** - JAF's functional architecture principles
- **[๐Ÿ“‹ API Reference](docs/api-reference.md)** - Complete Python API documentation
- **[๐Ÿ”ง Tools Guide](docs/tools.md)** - Creating and using tools
- **[๐Ÿ’พ Memory System](docs/memory-system.md)** - Persistence and memory providers
- **[๐Ÿค– Model Providers](docs/model-providers.md)** - LiteLLM integration
- **[๐ŸŒ Server API](docs/server-api.md)** - FastAPI endpoints reference
- **[๐Ÿ“ฆ Deployment](docs/deployment.md)** - Production deployment guide
- **[๐ŸŽฎ Examples](docs/examples.md)** - Detailed example walkthroughs
- **[๐Ÿ”ง Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions

## ๐Ÿ“ Project Structure

```
jaf-py/
โ”œโ”€โ”€ docs/                    # Complete documentation
โ”œโ”€โ”€ jaf/                     # Core framework package
โ”‚   โ”œโ”€โ”€ core/               # Core types and engine
โ”‚   โ”œโ”€โ”€ memory/             # Conversation persistence
โ”‚   โ”œโ”€โ”€ providers/          # External integrations (LiteLLM, MCP)
โ”‚   โ”œโ”€โ”€ policies/           # Validation and security
โ”‚   โ”œโ”€โ”€ server/             # FastAPI server
โ”‚   โ””โ”€โ”€ cli.py              # Command-line interface
โ”œโ”€โ”€ examples/               # Example applications
โ””โ”€โ”€ tests/                  # Test suite
```

## ๐ŸŽจ Architectural Visualization

JAF includes powerful visualization capabilities to help you understand and document your agent systems.

### Prerequisites

First, install the system Graphviz dependency:

```bash
# macOS
brew install graphviz

# Ubuntu/Debian  
sudo apt-get install graphviz

# Windows (via Chocolatey)
choco install graphviz
```

Then install JAF with visualization support:

```bash
pip install "jaf-py[visualization]"
```

### Quick Start

```python
import asyncio
from jaf import Agent, Tool, generate_agent_graph, GraphOptions

# Create your agents
agent = Agent(
    name='MyAgent',
    instructions=lambda state: "I am a helpful assistant.",
    tools=[my_tool],
    handoffs=['OtherAgent']
)

# Generate visualization
async def main():
    result = await generate_agent_graph(
        [agent],
        GraphOptions(
            title="My Agent System",
            output_path="./my-agents.png",
            color_scheme="modern",
            show_tool_details=True
        )
    )
    
    if result.success:
        print(f"โœ… Visualization saved to: {result.output_path}")
    else:
        print(f"โŒ Error: {result.error}")

asyncio.run(main())
```

### Features

- **๐ŸŽจ Multiple Color Schemes**: Choose from `default`, `modern`, or `minimal` themes
- **๐Ÿ“Š Agent Architecture**: Visualize agents, tools, and handoff relationships  
- **๐Ÿ”ง Tool Ecosystems**: Generate dedicated tool interaction diagrams
- **๐Ÿƒ Runner Architecture**: Show complete system architecture with session layers
- **๐Ÿ“„ Multiple Formats**: Export as PNG, SVG, or PDF
- **โš™๏ธ Customizable Layouts**: Support for various Graphviz layouts (`dot`, `circo`, `neato`, etc.)

### Example Output

The visualization system generates clear, professional diagrams showing:

- **Agent Nodes**: Rounded rectangles with agent names and model information
- **Tool Nodes**: Ellipses showing tool names and descriptions  
- **Handoff Edges**: Dashed lines indicating agent handoff relationships
- **Tool Connections**: Colored edges connecting agents to their tools
- **Cluster Organization**: Grouped components in runner architecture views

### Advanced Usage

```python
from jaf.visualization import run_visualization_examples

# Run comprehensive examples
await run_visualization_examples()

# This generates multiple example files:
# - ./examples/agent-graph.png (agent system overview)
# - ./examples/tool-graph.png (tool ecosystem)  
# - ./examples/runner-architecture.png (complete system)
# - ./examples/agent-modern.png (modern color scheme)
```

## ๐Ÿ—๏ธ Key Components

### Core Types

```python
from dataclasses import dataclass
from pydantic import BaseModel, Field
from jaf import Agent, Tool, RunState, run

# Define your context type
@dataclass
class MyContext:
    user_id: str
    permissions: list[str]

# Define tool schema
class CalculateArgs(BaseModel):
    expression: str = Field(description="Math expression to evaluate")

# Create a tool
class CalculatorTool:
    @property
    def schema(self):
        return type('ToolSchema', (), {
            'name': 'calculate',
            'description': 'Perform mathematical calculations',
            'parameters': CalculateArgs
        })()
    
    async def execute(self, args: CalculateArgs, context: MyContext) -> str:
        result = eval(args.expression)  # Don't do this in production!
        return f"{args.expression} = {result}"

# Define an agent
def create_math_agent():
    def instructions(state):
        return 'You are a helpful math tutor'
    
    return Agent(
        name='MathTutor',
        instructions=instructions,
        tools=[CalculatorTool()]
    )
```

### Running the Framework

```python
import asyncio
from jaf import run, make_litellm_provider, generate_run_id, generate_trace_id
from jaf.core.types import RunState, RunConfig, Message

async def main():
    model_provider = make_litellm_provider('http://localhost:4000')
    math_agent = create_math_agent()
    
    config = RunConfig(
        agent_registry={'MathTutor': math_agent},
        model_provider=model_provider,
        max_turns=10,
        on_event=lambda event: print(event),  # Real-time tracing
    )
    
    initial_state = RunState(
        run_id=generate_run_id(),
        trace_id=generate_trace_id(),
        messages=[Message(role='user', content='What is 2 + 2?')],
        current_agent_name='MathTutor',
        context=MyContext(user_id='user123', permissions=['user']),
        turn_count=0,
    )
    
    result = await run(initial_state, config)
    print(result.outcome.output if result.outcome.status == 'completed' else result.outcome.error)

asyncio.run(main())
```

## ๐Ÿ›ก๏ธ Security & Validation

### Composable Validation Policies

```python
from jaf.policies.validation import create_path_validator, create_permission_validator, compose_validations

# Create individual validators
path_validator = create_path_validator(['/shared', '/public'])
permission_validator = create_permission_validator('admin', lambda ctx: ctx)

# Compose them
combined_validator = compose_validations(path_validator, permission_validator)

# Apply to tools
secure_file_tool = with_validation(base_file_tool, combined_validator)
```

### Guardrails

```python
from jaf.policies.validation import create_content_filter, create_length_guardrail

config = RunConfig(
    # ... other config
    initial_input_guardrails=[
        create_content_filter(['spam', 'inappropriate']),  # Requires blocked patterns
        create_length_guardrail(max_length=1000, min_length=1)
    ],
    final_output_guardrails=[
        create_content_filter(['harmful', 'unsafe'])
    ],
)
```

## ๐Ÿ”— Agent Handoffs

```python
from jaf.policies.handoff import create_handoff_guardrail, HandoffPolicy
from pydantic import BaseModel
from enum import Enum

class AgentName(str, Enum):
    MATH_TUTOR = 'MathTutor'
    FILE_MANAGER = 'FileManager'

class HandoffOutput(BaseModel):
    agent_name: AgentName

def create_triage_agent():
    def instructions(state):
        return 'Route requests to specialized agents'
    
    return Agent(
        name='TriageAgent',
        instructions=instructions,
        tools=[],  # Regular tools would go here
        handoffs=['MathTutor', 'FileManager'],  # Allowed handoff targets
        output_schema=HandoffOutput,
    )
```

## ๐Ÿ“Š Observability

### Real-time Tracing

```python
from jaf.core.tracing import ConsoleTraceCollector, FileTraceCollector, create_composite_trace_collector

# Console logging
console_tracer = ConsoleTraceCollector()

# File logging
file_tracer = FileTraceCollector('./traces.log')

# Composite tracing
tracer = create_composite_trace_collector(console_tracer, file_tracer)

config = RunConfig(
    # ... other config
    on_event=tracer.collect,
)
```

### Error Handling

```python
from jaf.core.errors import JAFErrorHandler

if result.outcome.status == 'error':
    formatted_error = JAFErrorHandler.format_error(result.outcome.error)
    is_retryable = JAFErrorHandler.is_retryable(result.outcome.error)
    severity = JAFErrorHandler.get_severity(result.outcome.error)
    
    print(f"[{severity}] {formatted_error} (retryable: {is_retryable})")
```

## ๐Ÿ”Œ Provider Integrations

### A2A (Agent-to-Agent) Communication

JAF provides a robust A2A communication layer that allows agents to interact with each other. This is useful for building multi-agent systems where different agents have specialized skills.

```python
from jaf.a2a import create_a2a_agent, create_a2a_client, create_a2a_server

# Create agents
echo_agent = create_a2a_agent("EchoBot", "Echoes messages", "You are an echo bot.", [])
ping_agent = create_a2a_agent("PingBot", "Responds to pings", "You are a ping bot.", [])

# Create a server
server_config = {
    "agents": {"EchoBot": echo_agent, "PingBot": ping_agent},
    "agentCard": {"name": "Test Server"},
    "port": 8080,
}
server = create_a2a_server(server_config)

# Create a client
client = create_a2a_client("http://localhost:8080")
```

### LiteLLM Provider

```python
from jaf.providers.model import make_litellm_provider

# Connect to LiteLLM proxy for 100+ model support
model_provider = make_litellm_provider(
    'http://localhost:4000',  # LiteLLM proxy URL
    'your-api-key'           # Optional API key
)
```

### MCP (Model Context Protocol) Integration

JAF includes full Model Context Protocol support for seamless tool integration:

```python
from jaf.providers.mcp import create_mcp_stdio_client, create_mcp_tools_from_client

# Connect to MCP server via stdio
mcp_client = create_mcp_stdio_client(['python', '-m', 'my_mcp_server'])

# Initialize and get all available tools
await mcp_client.initialize()
mcp_tools = await create_mcp_tools_from_client(mcp_client)

# Use MCP tools in your agent
def create_mcp_agent():
    def instructions(state):
        return "You have access to powerful MCP tools for various tasks."
    
    return Agent(
        name='MCPAgent',
        instructions=instructions,
        tools=mcp_tools  # Automatically converted JAF tools
    )

# SSE client is also supported
from jaf.providers.mcp import create_mcp_sse_client
sse_client = create_mcp_sse_client('http://localhost:8080/sse')
```

## ๐Ÿš€ Development Server

JAF includes a built-in development server for testing agents locally via HTTP endpoints:

```python
from jaf.server import run_server
from jaf.providers.model import make_litellm_provider

def create_my_agent():
    def instructions(state):
        return 'You are a helpful assistant'
    
    return Agent(
        name='MyAgent',
        instructions=instructions,
        tools=[calculator_tool, greeting_tool]
    )

model_provider = make_litellm_provider('http://localhost:4000')

# Start server on port 3000
await run_server(
    [create_my_agent()], 
    {'model_provider': model_provider},
    {'port': 3000}
)
```

Server provides RESTful endpoints:
- `GET /health` - Health check
- `GET /agents` - List available agents  
- `POST /chat` - General chat endpoint
- `POST /agents/{name}/chat` - Agent-specific endpoint

## ๐Ÿ”ง Function Composition

JAF supports functional composition patterns for building complex behaviors from simple, reusable functions:

```python
from jaf import create_function_tool, ToolSource

# Enhanced tool with caching and retry
def with_cache(tool_func):
    cache = {}
    async def cached_execute(args, context):
        cache_key = str(args)
        if cache_key in cache:
            return cache[cache_key]
        result = await tool_func(args, context)
        if result.status == "success":
            cache[cache_key] = result
        return result
    return cached_execute

# Create enhanced tools by composition
enhanced_tool = create_function_tool({
    'name': 'enhanced_search',
    'description': 'Search with caching',
    'execute': with_cache(base_search_function),
    'parameters': SearchArgs,
    'source': ToolSource.NATIVE
})
```

**Key Benefits:**
- **Reusability**: Write once, compose everywhere
- **Testability**: Each function can be tested in isolation  
- **Type Safety**: Full type checking support
- **Performance**: Optimize individual pieces independently

## ๐ŸŽฎ Example Applications

Explore the example applications to see the framework in action:

### 1. Multi-Agent Server Demo

```bash
cd examples
python server_example.py
```

**Features demonstrated:**
- โœ… Multiple specialized agents (math, weather, general)
- โœ… Tool integration (calculator, weather API)
- โœ… Agent handoffs and routing
- โœ… RESTful API with auto-documentation
- โœ… Real-time tracing and error handling
- โœ… Production-ready server configuration

**Available endpoints:**
- `GET /health` - Server health check
- `GET /agents` - List all available agents
- `POST /chat` - Chat with any agent
- `GET /docs` - Interactive API documentation

### 2. MCP Integration Demo

```bash
cd examples/mcp_demo  
python main.py
```

**Features demonstrated:**
- โœ… Model Context Protocol integration
- โœ… Dynamic tool loading from MCP servers
- โœ… Secure filesystem operations
- โœ… MCP client configuration and management

## ๐Ÿงช Testing

```bash
pytest          # Run tests
ruff check .    # Lint code
mypy .          # Type checking
black .         # Format code
```

## ๐Ÿ›๏ธ Architecture Principles

### Immutable State Machine
- All state transformations create new state objects
- No mutation of existing data structures
- Predictable, testable state transitions

### Type Safety
- Runtime validation with Pydantic schemas
- Compile-time safety with Python type hints
- NewType for type-safe identifiers

### Pure Functions
- Core logic is side-effect free
- Easy to test and reason about
- Deterministic behavior

### Effect Isolation
- Side effects only in Provider modules
- Clear boundaries between pure and impure code
- Easier mocking and testing

## ๐Ÿ“œ License

MIT

## ๐Ÿค Contributing

1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Run the test suite
5. Submit a pull request

---

**JAF (Juspay Agentic Framework) v2.0** - Building the future of functional AI agent systems ๐Ÿš€

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "jaf-py",
    "maintainer": "JAF Contributors",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "ai, agents, functional, python, llm, mcp, model-context-protocol, agent-framework, functional-programming",
    "author": "JAF Contributors",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/53/a4/a655b535f42f71e2478f7f37a9d4a3f72b126a3091dc682dcfaecdc71c8e/jaf_py-2.2.0.tar.gz",
    "platform": null,
    "description": "# JAF (Juspay Agent Framework) - Python Implementation\n\n<!-- ![JAF Banner](docs/cover.png) -->\n\n[![Version](https://img.shields.io/badge/version-2.0.0-blue.svg)](https://github.com/xynehq/jaf-py)\n[![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/)\n[![Docs](https://img.shields.io/badge/Docs-Live-brightgreen)](https://xynehq.github.io/jaf-py/)\n\nA purely functional agent framework with immutable state and composable tools, professionally converted from TypeScript to Python. JAF enables building production-ready AI agent systems with built-in security, observability, and error handling.\n\n**\ud83c\udfaf Production Ready**: Complete feature parity with TypeScript version, comprehensive test suite, and production deployment support.\n\n## \ud83d\udcda **[Read the Full Documentation](https://xynehq.github.io/jaf-py/)**\n\n**[\ud83d\ude80 Get Started \u2192](https://xynehq.github.io/jaf-py/getting-started/)** | **[\ud83d\udcd6 API Reference \u2192](https://xynehq.github.io/jaf-py/api-reference/)** | **[\ud83c\udfae Examples \u2192](https://xynehq.github.io/jaf-py/examples/)**\n\n## \u2728 Key Features\n\n### \ud83c\udfd7\ufe0f **Complete TypeScript Conversion**\n- \u2705 **Full Feature Parity**: All TypeScript functionality converted to Python\n- \u2705 **Type Safety**: Pydantic models with runtime validation\n- \u2705 **Immutable State**: Functional programming principles preserved\n- \u2705 **Tool Integration**: Complete tool calling and execution system\n\n### \ud83d\ude80 **Production Ready Server**\n- \u2705 **FastAPI Server**: High-performance async HTTP API\n- \u2705 **Auto Documentation**: Interactive API docs at `/docs`\n- \u2705 **Health Monitoring**: Built-in health checks and metrics\n- \u2705 **CORS Support**: Ready for browser integration\n\n### \ud83d\udd0c **Model Context Protocol (MCP)**\n- \u2705 **MCP Client**: Full MCP specification support\n- \u2705 **Stdio & SSE**: Multiple transport protocols\n- \u2705 **Tool Integration**: Seamless MCP tool integration\n- \u2705 **Auto Discovery**: Dynamic tool loading from MCP servers\n\n### \ud83d\udee1\ufe0f **Enterprise Security**\n- \u2705 **Input Guardrails**: Content filtering and validation\n- \u2705 **Output Guardrails**: Response sanitization\n- \u2705 **Permission System**: Role-based access control\n- \u2705 **Audit Logging**: Complete interaction tracing\n\n### \ud83d\udcca **Observability & Monitoring**\n- \u2705 **Real-time Tracing**: Event-driven observability\n- \u2705 **Structured Logging**: JSON-formatted logs\n- \u2705 **Error Handling**: Comprehensive error types and recovery\n- \u2705 **Performance Metrics**: Built-in timing and counters\n\n### \ud83d\udd27 **Developer Experience**\n- \u2705 **CLI Tools**: Project initialization and management\n- \u2705 **Hot Reload**: Development server with auto-reload\n- \u2705 **Type Hints**: Full mypy compatibility\n- \u2705 **Rich Examples**: RAG, multi-agent, and server demos\n- \u2705 **Visual Architecture**: Graphviz-powered agent and tool diagrams\n\n## \ud83c\udfaf Core Philosophy\n\n- **Immutability**: All core data structures are deeply immutable\n- **Pure Functions**: Core logic expressed as pure, predictable functions\n- **Effects at the Edge**: Side effects isolated in Provider modules\n- **Composition over Configuration**: Build complex behavior by composing simple functions\n- **Type-Safe by Design**: Leverages Python's type system with Pydantic for runtime safety\n\n## \ud83d\ude80 Quick Start\n\n### Installation\n\n```bash\n# Install from GitHub (development version)\npip install git+https://github.com/xynehq/jaf-py.git\n\n# Or install with all optional dependencies\npip install \"jaf-py[all] @ git+https://github.com/xynehq/jaf-py.git\"\n\n# Install specific feature sets\npip install \"jaf-py[server] @ git+https://github.com/xynehq/jaf-py.git\"        # FastAPI server support\npip install \"jaf-py[memory] @ git+https://github.com/xynehq/jaf-py.git\"        # Redis/PostgreSQL memory providers\npip install \"jaf-py[visualization] @ git+https://github.com/xynehq/jaf-py.git\" # Graphviz visualization tools\npip install \"jaf-py[dev] @ git+https://github.com/xynehq/jaf-py.git\"           # Development tools\n```\n\n### CLI Usage\n\nJAF includes a powerful CLI for project management:\n\n```bash\n# Initialize a new JAF project\njaf init my-agent-project\n\n# Run the development server\njaf server --host 0.0.0.0 --port 8000\n\n# Show version and help\njaf version\njaf --help\n```\n\n### Development Setup\n\n```bash\ngit clone https://github.com/xynehq/jaf-py\ncd jaf-py\npip install -e \".[dev]\"\n\n# Run tests\npytest\n\n# Type checking and linting\nmypy jaf/\nruff check jaf/\nblack jaf/\n\n# Documentation\npip install -r requirements-docs.txt\n./docs.sh serve  # Start documentation server\n./docs.sh deploy # Deploy to GitHub Pages\n```\n\n## \ud83d\udcd6 Documentation\n\n### \ud83c\udf10 **[Official Documentation Website](https://xynehq.github.io/jaf-py/)**\n\nThe complete, searchable documentation is available at **[xynehq.github.io/jaf-py](https://xynehq.github.io/jaf-py/)** with:\n\n- \u2705 **Interactive navigation** with search and filtering\n- \u2705 **Dark/light mode** with automatic system preference detection  \n- \u2705 **Mobile-responsive design** for documentation on any device\n- \u2705 **Live code examples** with syntax highlighting\n- \u2705 **API reference** with auto-generated documentation\n- \u2705 **Always up-to-date** with automatic deployments\n\n### \ud83d\udcc1 **Local Documentation**\n\nFor offline access, documentation is also available in the [`docs/`](docs/) directory:\n\n- **[\ud83d\udcda Documentation Hub](docs/README.md)** - Your starting point for all documentation\n- **[\ud83d\ude80 Getting Started](docs/getting-started.md)** - Installation and first agent tutorial\n- **[\ud83c\udfd7\ufe0f Core Concepts](docs/core-concepts.md)** - JAF's functional architecture principles\n- **[\ud83d\udccb API Reference](docs/api-reference.md)** - Complete Python API documentation\n- **[\ud83d\udd27 Tools Guide](docs/tools.md)** - Creating and using tools\n- **[\ud83d\udcbe Memory System](docs/memory-system.md)** - Persistence and memory providers\n- **[\ud83e\udd16 Model Providers](docs/model-providers.md)** - LiteLLM integration\n- **[\ud83c\udf10 Server API](docs/server-api.md)** - FastAPI endpoints reference\n- **[\ud83d\udce6 Deployment](docs/deployment.md)** - Production deployment guide\n- **[\ud83c\udfae Examples](docs/examples.md)** - Detailed example walkthroughs\n- **[\ud83d\udd27 Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions\n\n## \ud83d\udcc1 Project Structure\n\n```\njaf-py/\n\u251c\u2500\u2500 docs/                    # Complete documentation\n\u251c\u2500\u2500 jaf/                     # Core framework package\n\u2502   \u251c\u2500\u2500 core/               # Core types and engine\n\u2502   \u251c\u2500\u2500 memory/             # Conversation persistence\n\u2502   \u251c\u2500\u2500 providers/          # External integrations (LiteLLM, MCP)\n\u2502   \u251c\u2500\u2500 policies/           # Validation and security\n\u2502   \u251c\u2500\u2500 server/             # FastAPI server\n\u2502   \u2514\u2500\u2500 cli.py              # Command-line interface\n\u251c\u2500\u2500 examples/               # Example applications\n\u2514\u2500\u2500 tests/                  # Test suite\n```\n\n## \ud83c\udfa8 Architectural Visualization\n\nJAF includes powerful visualization capabilities to help you understand and document your agent systems.\n\n### Prerequisites\n\nFirst, install the system Graphviz dependency:\n\n```bash\n# macOS\nbrew install graphviz\n\n# Ubuntu/Debian  \nsudo apt-get install graphviz\n\n# Windows (via Chocolatey)\nchoco install graphviz\n```\n\nThen install JAF with visualization support:\n\n```bash\npip install \"jaf-py[visualization]\"\n```\n\n### Quick Start\n\n```python\nimport asyncio\nfrom jaf import Agent, Tool, generate_agent_graph, GraphOptions\n\n# Create your agents\nagent = Agent(\n    name='MyAgent',\n    instructions=lambda state: \"I am a helpful assistant.\",\n    tools=[my_tool],\n    handoffs=['OtherAgent']\n)\n\n# Generate visualization\nasync def main():\n    result = await generate_agent_graph(\n        [agent],\n        GraphOptions(\n            title=\"My Agent System\",\n            output_path=\"./my-agents.png\",\n            color_scheme=\"modern\",\n            show_tool_details=True\n        )\n    )\n    \n    if result.success:\n        print(f\"\u2705 Visualization saved to: {result.output_path}\")\n    else:\n        print(f\"\u274c Error: {result.error}\")\n\nasyncio.run(main())\n```\n\n### Features\n\n- **\ud83c\udfa8 Multiple Color Schemes**: Choose from `default`, `modern`, or `minimal` themes\n- **\ud83d\udcca Agent Architecture**: Visualize agents, tools, and handoff relationships  \n- **\ud83d\udd27 Tool Ecosystems**: Generate dedicated tool interaction diagrams\n- **\ud83c\udfc3 Runner Architecture**: Show complete system architecture with session layers\n- **\ud83d\udcc4 Multiple Formats**: Export as PNG, SVG, or PDF\n- **\u2699\ufe0f Customizable Layouts**: Support for various Graphviz layouts (`dot`, `circo`, `neato`, etc.)\n\n### Example Output\n\nThe visualization system generates clear, professional diagrams showing:\n\n- **Agent Nodes**: Rounded rectangles with agent names and model information\n- **Tool Nodes**: Ellipses showing tool names and descriptions  \n- **Handoff Edges**: Dashed lines indicating agent handoff relationships\n- **Tool Connections**: Colored edges connecting agents to their tools\n- **Cluster Organization**: Grouped components in runner architecture views\n\n### Advanced Usage\n\n```python\nfrom jaf.visualization import run_visualization_examples\n\n# Run comprehensive examples\nawait run_visualization_examples()\n\n# This generates multiple example files:\n# - ./examples/agent-graph.png (agent system overview)\n# - ./examples/tool-graph.png (tool ecosystem)  \n# - ./examples/runner-architecture.png (complete system)\n# - ./examples/agent-modern.png (modern color scheme)\n```\n\n## \ud83c\udfd7\ufe0f Key Components\n\n### Core Types\n\n```python\nfrom dataclasses import dataclass\nfrom pydantic import BaseModel, Field\nfrom jaf import Agent, Tool, RunState, run\n\n# Define your context type\n@dataclass\nclass MyContext:\n    user_id: str\n    permissions: list[str]\n\n# Define tool schema\nclass CalculateArgs(BaseModel):\n    expression: str = Field(description=\"Math expression to evaluate\")\n\n# Create a tool\nclass CalculatorTool:\n    @property\n    def schema(self):\n        return type('ToolSchema', (), {\n            'name': 'calculate',\n            'description': 'Perform mathematical calculations',\n            'parameters': CalculateArgs\n        })()\n    \n    async def execute(self, args: CalculateArgs, context: MyContext) -> str:\n        result = eval(args.expression)  # Don't do this in production!\n        return f\"{args.expression} = {result}\"\n\n# Define an agent\ndef create_math_agent():\n    def instructions(state):\n        return 'You are a helpful math tutor'\n    \n    return Agent(\n        name='MathTutor',\n        instructions=instructions,\n        tools=[CalculatorTool()]\n    )\n```\n\n### Running the Framework\n\n```python\nimport asyncio\nfrom jaf import run, make_litellm_provider, generate_run_id, generate_trace_id\nfrom jaf.core.types import RunState, RunConfig, Message\n\nasync def main():\n    model_provider = make_litellm_provider('http://localhost:4000')\n    math_agent = create_math_agent()\n    \n    config = RunConfig(\n        agent_registry={'MathTutor': math_agent},\n        model_provider=model_provider,\n        max_turns=10,\n        on_event=lambda event: print(event),  # Real-time tracing\n    )\n    \n    initial_state = RunState(\n        run_id=generate_run_id(),\n        trace_id=generate_trace_id(),\n        messages=[Message(role='user', content='What is 2 + 2?')],\n        current_agent_name='MathTutor',\n        context=MyContext(user_id='user123', permissions=['user']),\n        turn_count=0,\n    )\n    \n    result = await run(initial_state, config)\n    print(result.outcome.output if result.outcome.status == 'completed' else result.outcome.error)\n\nasyncio.run(main())\n```\n\n## \ud83d\udee1\ufe0f Security & Validation\n\n### Composable Validation Policies\n\n```python\nfrom jaf.policies.validation import create_path_validator, create_permission_validator, compose_validations\n\n# Create individual validators\npath_validator = create_path_validator(['/shared', '/public'])\npermission_validator = create_permission_validator('admin', lambda ctx: ctx)\n\n# Compose them\ncombined_validator = compose_validations(path_validator, permission_validator)\n\n# Apply to tools\nsecure_file_tool = with_validation(base_file_tool, combined_validator)\n```\n\n### Guardrails\n\n```python\nfrom jaf.policies.validation import create_content_filter, create_length_guardrail\n\nconfig = RunConfig(\n    # ... other config\n    initial_input_guardrails=[\n        create_content_filter(['spam', 'inappropriate']),  # Requires blocked patterns\n        create_length_guardrail(max_length=1000, min_length=1)\n    ],\n    final_output_guardrails=[\n        create_content_filter(['harmful', 'unsafe'])\n    ],\n)\n```\n\n## \ud83d\udd17 Agent Handoffs\n\n```python\nfrom jaf.policies.handoff import create_handoff_guardrail, HandoffPolicy\nfrom pydantic import BaseModel\nfrom enum import Enum\n\nclass AgentName(str, Enum):\n    MATH_TUTOR = 'MathTutor'\n    FILE_MANAGER = 'FileManager'\n\nclass HandoffOutput(BaseModel):\n    agent_name: AgentName\n\ndef create_triage_agent():\n    def instructions(state):\n        return 'Route requests to specialized agents'\n    \n    return Agent(\n        name='TriageAgent',\n        instructions=instructions,\n        tools=[],  # Regular tools would go here\n        handoffs=['MathTutor', 'FileManager'],  # Allowed handoff targets\n        output_schema=HandoffOutput,\n    )\n```\n\n## \ud83d\udcca Observability\n\n### Real-time Tracing\n\n```python\nfrom jaf.core.tracing import ConsoleTraceCollector, FileTraceCollector, create_composite_trace_collector\n\n# Console logging\nconsole_tracer = ConsoleTraceCollector()\n\n# File logging\nfile_tracer = FileTraceCollector('./traces.log')\n\n# Composite tracing\ntracer = create_composite_trace_collector(console_tracer, file_tracer)\n\nconfig = RunConfig(\n    # ... other config\n    on_event=tracer.collect,\n)\n```\n\n### Error Handling\n\n```python\nfrom jaf.core.errors import JAFErrorHandler\n\nif result.outcome.status == 'error':\n    formatted_error = JAFErrorHandler.format_error(result.outcome.error)\n    is_retryable = JAFErrorHandler.is_retryable(result.outcome.error)\n    severity = JAFErrorHandler.get_severity(result.outcome.error)\n    \n    print(f\"[{severity}] {formatted_error} (retryable: {is_retryable})\")\n```\n\n## \ud83d\udd0c Provider Integrations\n\n### A2A (Agent-to-Agent) Communication\n\nJAF provides a robust A2A communication layer that allows agents to interact with each other. This is useful for building multi-agent systems where different agents have specialized skills.\n\n```python\nfrom jaf.a2a import create_a2a_agent, create_a2a_client, create_a2a_server\n\n# Create agents\necho_agent = create_a2a_agent(\"EchoBot\", \"Echoes messages\", \"You are an echo bot.\", [])\nping_agent = create_a2a_agent(\"PingBot\", \"Responds to pings\", \"You are a ping bot.\", [])\n\n# Create a server\nserver_config = {\n    \"agents\": {\"EchoBot\": echo_agent, \"PingBot\": ping_agent},\n    \"agentCard\": {\"name\": \"Test Server\"},\n    \"port\": 8080,\n}\nserver = create_a2a_server(server_config)\n\n# Create a client\nclient = create_a2a_client(\"http://localhost:8080\")\n```\n\n### LiteLLM Provider\n\n```python\nfrom jaf.providers.model import make_litellm_provider\n\n# Connect to LiteLLM proxy for 100+ model support\nmodel_provider = make_litellm_provider(\n    'http://localhost:4000',  # LiteLLM proxy URL\n    'your-api-key'           # Optional API key\n)\n```\n\n### MCP (Model Context Protocol) Integration\n\nJAF includes full Model Context Protocol support for seamless tool integration:\n\n```python\nfrom jaf.providers.mcp import create_mcp_stdio_client, create_mcp_tools_from_client\n\n# Connect to MCP server via stdio\nmcp_client = create_mcp_stdio_client(['python', '-m', 'my_mcp_server'])\n\n# Initialize and get all available tools\nawait mcp_client.initialize()\nmcp_tools = await create_mcp_tools_from_client(mcp_client)\n\n# Use MCP tools in your agent\ndef create_mcp_agent():\n    def instructions(state):\n        return \"You have access to powerful MCP tools for various tasks.\"\n    \n    return Agent(\n        name='MCPAgent',\n        instructions=instructions,\n        tools=mcp_tools  # Automatically converted JAF tools\n    )\n\n# SSE client is also supported\nfrom jaf.providers.mcp import create_mcp_sse_client\nsse_client = create_mcp_sse_client('http://localhost:8080/sse')\n```\n\n## \ud83d\ude80 Development Server\n\nJAF includes a built-in development server for testing agents locally via HTTP endpoints:\n\n```python\nfrom jaf.server import run_server\nfrom jaf.providers.model import make_litellm_provider\n\ndef create_my_agent():\n    def instructions(state):\n        return 'You are a helpful assistant'\n    \n    return Agent(\n        name='MyAgent',\n        instructions=instructions,\n        tools=[calculator_tool, greeting_tool]\n    )\n\nmodel_provider = make_litellm_provider('http://localhost:4000')\n\n# Start server on port 3000\nawait run_server(\n    [create_my_agent()], \n    {'model_provider': model_provider},\n    {'port': 3000}\n)\n```\n\nServer provides RESTful endpoints:\n- `GET /health` - Health check\n- `GET /agents` - List available agents  \n- `POST /chat` - General chat endpoint\n- `POST /agents/{name}/chat` - Agent-specific endpoint\n\n## \ud83d\udd27 Function Composition\n\nJAF supports functional composition patterns for building complex behaviors from simple, reusable functions:\n\n```python\nfrom jaf import create_function_tool, ToolSource\n\n# Enhanced tool with caching and retry\ndef with_cache(tool_func):\n    cache = {}\n    async def cached_execute(args, context):\n        cache_key = str(args)\n        if cache_key in cache:\n            return cache[cache_key]\n        result = await tool_func(args, context)\n        if result.status == \"success\":\n            cache[cache_key] = result\n        return result\n    return cached_execute\n\n# Create enhanced tools by composition\nenhanced_tool = create_function_tool({\n    'name': 'enhanced_search',\n    'description': 'Search with caching',\n    'execute': with_cache(base_search_function),\n    'parameters': SearchArgs,\n    'source': ToolSource.NATIVE\n})\n```\n\n**Key Benefits:**\n- **Reusability**: Write once, compose everywhere\n- **Testability**: Each function can be tested in isolation  \n- **Type Safety**: Full type checking support\n- **Performance**: Optimize individual pieces independently\n\n## \ud83c\udfae Example Applications\n\nExplore the example applications to see the framework in action:\n\n### 1. Multi-Agent Server Demo\n\n```bash\ncd examples\npython server_example.py\n```\n\n**Features demonstrated:**\n- \u2705 Multiple specialized agents (math, weather, general)\n- \u2705 Tool integration (calculator, weather API)\n- \u2705 Agent handoffs and routing\n- \u2705 RESTful API with auto-documentation\n- \u2705 Real-time tracing and error handling\n- \u2705 Production-ready server configuration\n\n**Available endpoints:**\n- `GET /health` - Server health check\n- `GET /agents` - List all available agents\n- `POST /chat` - Chat with any agent\n- `GET /docs` - Interactive API documentation\n\n### 2. MCP Integration Demo\n\n```bash\ncd examples/mcp_demo  \npython main.py\n```\n\n**Features demonstrated:**\n- \u2705 Model Context Protocol integration\n- \u2705 Dynamic tool loading from MCP servers\n- \u2705 Secure filesystem operations\n- \u2705 MCP client configuration and management\n\n## \ud83e\uddea Testing\n\n```bash\npytest          # Run tests\nruff check .    # Lint code\nmypy .          # Type checking\nblack .         # Format code\n```\n\n## \ud83c\udfdb\ufe0f Architecture Principles\n\n### Immutable State Machine\n- All state transformations create new state objects\n- No mutation of existing data structures\n- Predictable, testable state transitions\n\n### Type Safety\n- Runtime validation with Pydantic schemas\n- Compile-time safety with Python type hints\n- NewType for type-safe identifiers\n\n### Pure Functions\n- Core logic is side-effect free\n- Easy to test and reason about\n- Deterministic behavior\n\n### Effect Isolation\n- Side effects only in Provider modules\n- Clear boundaries between pure and impure code\n- Easier mocking and testing\n\n## \ud83d\udcdc License\n\nMIT\n\n## \ud83e\udd1d Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Add tests for new functionality\n4. Run the test suite\n5. Submit a pull request\n\n---\n\n**JAF (Juspay Agentic Framework) v2.0** - Building the future of functional AI agent systems \ud83d\ude80\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A purely functional agent framework with immutable state and composable tools - Python implementation",
    "version": "2.2.0",
    "project_urls": {
        "Changelog": "https://github.com/xynehq/jaf-py/releases",
        "Documentation": "https://xynehq.github.io/jaf-py/",
        "Homepage": "https://github.com/xynehq/jaf-py",
        "Issues": "https://github.com/xynehq/jaf-py/issues",
        "Repository": "https://github.com/xynehq/jaf-py"
    },
    "split_keywords": [
        "ai",
        " agents",
        " functional",
        " python",
        " llm",
        " mcp",
        " model-context-protocol",
        " agent-framework",
        " functional-programming"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "460bfa0675a95ac085c34cf4b36ae8b2a035396d52f887c79f317b6b79b1aa30",
                "md5": "fca8c27dfa75db1c75fe0f6101378bec",
                "sha256": "b0dfabb2577bb93bd1524584f09ec2d37bb9e24799fa853b78fb3917f8221a39"
            },
            "downloads": -1,
            "filename": "jaf_py-2.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fca8c27dfa75db1c75fe0f6101378bec",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 234636,
            "upload_time": "2025-08-28T17:15:12",
            "upload_time_iso_8601": "2025-08-28T17:15:12.260484Z",
            "url": "https://files.pythonhosted.org/packages/46/0b/fa0675a95ac085c34cf4b36ae8b2a035396d52f887c79f317b6b79b1aa30/jaf_py-2.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "53a4a655b535f42f71e2478f7f37a9d4a3f72b126a3091dc682dcfaecdc71c8e",
                "md5": "44b52613022796ad5b94e2f6fb159dff",
                "sha256": "59e4797e00baa3be0c610de4386f09e0cd7104e8ae8e094567e70d43e5948860"
            },
            "downloads": -1,
            "filename": "jaf_py-2.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "44b52613022796ad5b94e2f6fb159dff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 281614,
            "upload_time": "2025-08-28T17:15:14",
            "upload_time_iso_8601": "2025-08-28T17:15:14.079733Z",
            "url": "https://files.pythonhosted.org/packages/53/a4/a655b535f42f71e2478f7f37a9d4a3f72b126a3091dc682dcfaecdc71c8e/jaf_py-2.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-28 17:15:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "xynehq",
    "github_project": "jaf-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "jaf-py"
}
        
Elapsed time: 0.46058s