Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
include pyagenity.json
include agentflow.json
include *.md
include LICENSE*
include requirements.txt
include example_weather_agent.py
recursive-include pyagenity_api *.json
recursive-include pyagenity_api *.yaml
recursive-include pyagenity_api *.yml
recursive-include pyagenity_api *.py
recursive-include agentflow_cli *.json
recursive-include agentflow_cli *.yaml
recursive-include agentflow_cli *.yml
recursive-include agentflow_cli *.py
recursive-include src *.json
recursive-include src *.yaml
recursive-include src *.yml
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Makefile for PyAgenity packaging and publishing
# Makefile for Agentflow packaging and publishing

.PHONY: build publish testpublish clean test test-cov

Expand Down Expand Up @@ -29,4 +29,4 @@ docs-build:
mkdocs build --strict

test-cov:
uv run pytest --cov=pyagenity --cov-report=html --cov-report=term-missing --cov-report=xml -v
uv run pytest --cov=agentflow-cli --cov-report=html --cov-report=term-missing --cov-report=xml -v
68 changes: 34 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@

# Pyagenity API
# AgentFlow CLI

A Python API framework with GraphQL support, task management, and CLI tools for building scalable web applications.

## Installation

### From PyPI (Recommended)
```bash
pip install pyagenity-api
pip install agentflow-cli
```

### From Source
```bash
git clone https://github.com/Iamsdt/pyagenity-api.git
cd pyagenity-api
git clone https://github.com/Iamsdt/agentflow-cli.git
cd agentflow-cli
pip install -e .
```

## Quick Start

1. **Initialize a new project:**
```bash
pag init
agentflow init
```

2. **Start the API server with default configuration:**
```bash
pag api
agentflow api
```

3. **Start the API server with custom configuration:**
```bash
pag api --config custom-config.json
agentflow api --config custom-config.json
```

4. **Start the API server on different host/port:**
```bash
pag api --host 127.0.0.1 --port 9000
agentflow api --host 127.0.0.1 --port 9000
```

5. **Generate a Dockerfile for containerization:**
```bash
pag build
agentflow build
```

## CLI Commands

The `pag` command provides the following subcommands:
The `agentflow` command provides the following subcommands:

### `pag api`
### `agentflow api`
Start the Pyagenity API server.

**Options:**
- `--config TEXT`: Path to config file (default: pyagenity.json)
- `--config TEXT`: Path to config file (default: agentflow.json)
- `--host TEXT`: Host to run the API on (default: 0.0.0.0)
- `--port INTEGER`: Port to run the API on (default: 8000)
- `--reload/--no-reload`: Enable auto-reload (default: enabled)

**Examples:**
```bash
# Start with default configuration
pag api
agentflow api

# Start with custom config file
pag api --config my-config.json
agentflow api --config my-config.json

# Start on localhost only, port 9000
pag api --host 127.0.0.1 --port 9000
agentflow api --host 127.0.0.1 --port 9000

# Start without auto-reload
pag api --no-reload
agentflow api --no-reload
```

### `pag init`
### `agentflow init`
Initialize a new config file with default settings.

**Options:**
- `--output TEXT`: Output config file path (default: pyagenity.json)
- `--output TEXT`: Output config file path (default: agentflow.json)
- `--force`: Overwrite existing config file

**Examples:**
```bash
# Create default config
pag init
agentflow init

# Create config with custom name
pag init --output custom-config.json
agentflow init --output custom-config.json

# Overwrite existing config
pag init --force
agentflow init --force
```

### `pag version`
### `agentflow version`
Show the CLI version information.

```bash
pag version
agentflow version
```

### `pag build`
### `agentflow build`
Generate a Dockerfile for the Pyagenity API application.

**Options:**
Expand All @@ -110,29 +110,29 @@ Generate a Dockerfile for the Pyagenity API application.
**Examples:**
```bash
# Generate default Dockerfile
pag build
agentflow build

# Generate with custom Python version and port
pag build --python-version 3.12 --port 9000
agentflow build --python-version 3.12 --port 9000

# Overwrite existing Dockerfile
pag build --force
agentflow build --force

# Generate with custom filename
pag build --output MyDockerfile
agentflow build --output MyDockerfile
```

**Features:**
- 🔍 **Automatic requirements.txt detection**: Searches for requirements files in multiple locations
- ⚠️ **Smart fallback**: If no requirements.txt found, installs pyagenity-api from PyPI
- ⚠️ **Smart fallback**: If no requirements.txt found, installs agentflow-cli from PyPI
- 🐳 **Production-ready**: Generates optimized Dockerfile with security best practices
- 🔧 **Customizable**: Supports custom Python versions, ports, and output paths
- 🏥 **Health checks**: Includes built-in health check endpoint
- 👤 **Non-root user**: Runs container as non-root for security

## Configuration

The configuration file (`pyagenity.json`) supports the following structure:
The configuration file (`agentflow.json`) supports the following structure:

```json
{
Expand All @@ -147,7 +147,7 @@ The configuration file (`pyagenity.json`) supports the following structure:
"workers": 1
},
"database": {
"url": "sqlite://./pyagenity.db"
"url": "sqlite://./agentflowdb"
},
"redis": {
"url": "redis://localhost:6379"
Expand All @@ -166,7 +166,7 @@ The CLI automatically finds your config file in this order:
## Project Structure

```
pyagenity-api/
agentflow-cli/
├── pyagenity_api/ # Main package directory
│ ├── __init__.py # Package initialization
│ ├── cli.py # CLI module
Expand Down Expand Up @@ -346,8 +346,8 @@ If you prefer manual setup:

1. **Clone the repository:**
```bash
git clone https://github.com/Iamsdt/pyagenity-api.git
cd pyagenity-api
git clone https://github.com/Iamsdt/agentflow-cli.git
cd agentflow-cli
```

2. **Create a virtual environment:**
Expand Down
10 changes: 10 additions & 0 deletions Task.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ Lets execute api in below sequence, if any api fails then it should crash the sc
Note: using v1/graph/invoke will share thread_id, so we can use that thread_id to test checkpointer apis
1. /v1/threads/{thread_id}/state


# Thinking blocks not converted to reasoning blocks

"thinking_blocks": [
{
"type": "thinking",
"thinking": "{\"text\": \"Hello! How can I help you today?\"}",
"signature": "CpwCAdHtim9umxTi9N+7hzmLhJnA1tIWY59EIk7d6FiZeBb/Faqtq7w7GxIqIeQQ08pNPtUOYDf5Vtl9FCc/dGP9a+QHmq2xoygtMEHY1e6tTDExoOeyDTWoL6/jruOoTTyUHxr62D2sD5xn/zmKmj7EGl5qDT5cJJRhPt208GvTchpA38QcazDAWIDzrkmqQEh+zdXv9HhUOM57yXs1/PDAPZiF20lVdEnGibqfsUa640o2tDVCxnd5xbciPdxEx6wrVhXVm0bnKybgXNPw+xory715t93vL0gY6h1MS8GGJbyVNO+xRwUD5yxCSG4HNyGdT9Axhfv8w8SNfG4IetJFegn2Oz8Us22PYm1bcH+7w/5yAJ2To4RHWO7TkeQ="
}
]
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions agentflow_cli/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Pyagenity CLI package."""

__version__ = "1.0.0"
49 changes: 49 additions & 0 deletions agentflow_cli/cli/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""CLI command modules."""

from abc import ABC, abstractmethod
from typing import Any

from agentflow_cli.cli.core.output import OutputFormatter
from agentflow_cli.cli.logger import CLILoggerMixin


class BaseCommand(ABC, CLILoggerMixin):
"""Base class for all CLI commands."""

def __init__(self, output: OutputFormatter | None = None) -> None:
"""Initialize the base command.

Args:
output: Output formatter instance
"""
super().__init__()
self.output = output or OutputFormatter()

@abstractmethod
def execute(self, *args: Any, **kwargs: Any) -> int:
"""Execute the command.

Returns:
Exit code (0 for success, non-zero for failure)
"""

def handle_error(self, error: Exception) -> int:
"""Handle command errors consistently.

Args:
error: Exception that occurred

Returns:
Appropriate exit code
"""
self.logger.error("Command failed: %s", error)

# Import here to avoid circular imports
from agentflow_cli.cli.exceptions import PyagenityCLIError

if isinstance(error, PyagenityCLIError):
self.output.error(error.message)
return error.exit_code

self.output.error(f"Unexpected error: {error}")
return 1
98 changes: 98 additions & 0 deletions agentflow_cli/cli/commands/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""API server command implementation."""

import os
import sys
from pathlib import Path
from typing import Any

import uvicorn
from dotenv import load_dotenv

from agentflow_cli.cli.commands import BaseCommand
from agentflow_cli.cli.constants import DEFAULT_CONFIG_FILE, DEFAULT_HOST, DEFAULT_PORT
from agentflow_cli.cli.core.config import ConfigManager
from agentflow_cli.cli.core.validation import validate_cli_options
from agentflow_cli.cli.exceptions import ConfigurationError, ServerError


class APICommand(BaseCommand):
"""Command to start the Pyagenity API server."""

def execute(
self,
config: str = DEFAULT_CONFIG_FILE,
host: str = DEFAULT_HOST,
port: int = DEFAULT_PORT,
reload: bool = True,
**kwargs: Any,
) -> int:
"""Execute the API server command.

Args:
config: Path to config file
host: Host to bind to
port: Port to bind to
reload: Enable auto-reload
**kwargs: Additional arguments

Returns:
Exit code
"""
try:
# Print banner
self.output.print_banner(
"API (development)",
"Starting development server via Uvicorn. Not for production use.",
)

# Validate inputs
validated_options = validate_cli_options(host, port, config)

# Load configuration
config_manager = ConfigManager()
actual_config_path = config_manager.find_config_file(validated_options["config"])
# Load and validate config
config_manager.load_config(str(actual_config_path))

# Load environment file if specified
env_file_path = config_manager.resolve_env_file()
if env_file_path:
self.logger.info("Loading environment from: %s", env_file_path)
load_dotenv(env_file_path)
else:
# Load default .env if it exists
load_dotenv()

# Set environment variables
os.environ["GRAPH_PATH"] = str(actual_config_path)

# Ensure we're using the correct module path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))

self.logger.info(
"Starting API with config: %s, host: %s, port: %d",
actual_config_path,
validated_options["host"],
validated_options["port"],
)

# Start the server
uvicorn.run(
"agentflow_cli.src.app.main:app",
host=validated_options["host"],
port=validated_options["port"],
reload=reload,
workers=1,
)

return 0

except (ConfigurationError, ServerError) as e:
return self.handle_error(e)
except Exception as e:
server_error = ServerError(
f"Failed to start API server: {e}",
host=host,
port=port,
)
return self.handle_error(server_error)
Loading
Loading