Metadata-Version: 2.4
Name: agentinc-sdk
Version: 0.2.0
Summary: Developer SDK for the Agentinc agent marketplace platform
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.12
Requires-Dist: pydantic>=2.7
Provides-Extra: all
Requires-Dist: anthropic>=0.25; extra == 'all'
Requires-Dist: fastapi>=0.115; extra == 'all'
Requires-Dist: google-genai>=1.0; extra == 'all'
Requires-Dist: mcp>=1.0; extra == 'all'
Requires-Dist: openai>=1.0; extra == 'all'
Requires-Dist: redis>=5.0; extra == 'all'
Requires-Dist: sse-starlette>=2.0; extra == 'all'
Requires-Dist: uvicorn[standard]>=0.34; extra == 'all'
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.25; extra == 'anthropic'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=1.3; extra == 'dev'
Requires-Dist: pytest-mock>=3.0; extra == 'dev'
Requires-Dist: pytest>=9.0; extra == 'dev'
Provides-Extra: gemini
Requires-Dist: google-genai>=1.0; extra == 'gemini'
Provides-Extra: mcp
Requires-Dist: mcp>=1.0; extra == 'mcp'
Provides-Extra: memory
Requires-Dist: redis>=5.0; extra == 'memory'
Provides-Extra: openai
Requires-Dist: openai>=1.0; extra == 'openai'
Provides-Extra: serve
Requires-Dist: fastapi>=0.115; extra == 'serve'
Requires-Dist: sse-starlette>=2.0; extra == 'serve'
Requires-Dist: uvicorn[standard]>=0.34; extra == 'serve'
Description-Content-Type: text/markdown

# agentinc-sdk

The developer SDK for the [Agentinc](https://withagentinc.com) agent marketplace platform.

Declare an agent with `Agent()` — give it a role, model, tools, memory, or MCP connections — and serve it over [A2A](https://google.github.io/A2A/). The SDK handles provider selection, tool dispatch, session memory, and streaming automatically.

## Install

```bash
pip install agentinc-sdk                    # core (pydantic only)
pip install 'agentinc-sdk[openai,serve]'    # OpenAI + A2A server
pip install 'agentinc-sdk[anthropic,serve]' # Anthropic + A2A server
pip install 'agentinc-sdk[all]'             # everything
```

Requires **Python 3.12+**.

## Agent Skill

Install the agentinc-sdk skill so your coding agent understands the SDK and can help you build agents:

```bash
npx skills add agentinc/sdk
```

Your coding agent will automatically use it when working with `Agent()`, `AgentProtocol`, `@tool`, `serve()`, and all framework integration patterns.

## Quickstart

```python
import os
from agentinc.sdk import Agent
from agentinc.sdk.serve import serve

def get_weather(city: str) -> str:
    """Gets the current weather for a city."""
    return f"72°F and sunny in {city}"

agent = Agent(
    role="You are a helpful assistant.",
    model={"model": "gpt-4o-mini", "api_key": os.environ["OPENAI_API_KEY"]},
    tools=[get_weather],
)

serve(agent, name="my-agent", port=8000)
```

```bash
curl -X POST http://localhost:8000 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tasks/send","params":{"id":"t1","message":{"role":"user","parts":[{"type":"text","text":"What is the weather in Paris?"}]}}}'
```

## Agent Constructor

```python
Agent(
    role:    str,                      # system prompt / persona
    model:   ModelConfig,              # provider + credentials
    tools:   list[Callable] = [],      # plain Python functions — auto-wrapped
    mcps:    list[MCPConfig] = [],     # MCP server connections
    memory:  MemoryConfig | None = None,  # Redis-backed session memory
    context: str | None = None,        # extra context appended to system prompt
    data:    DataConfig | None = None, # RAG config (reserved, not yet implemented)
)
```

### ModelConfig — provider is auto-detected from model name

```python
{"model": "gpt-4o-mini",       "api_key": "sk-..."}           # OpenAI
{"model": "claude-sonnet-4-6", "api_key": "sk-ant-..."}        # Anthropic
{"model": "gemini-1.5-pro",    "api_key": "..."}               # Gemini
{"model": "deepseek-chat",     "api_key": "sk-...", "base_url": "https://api.deepseek.com"}  # any OpenAI-compatible
```

### With Redis memory

```python
agent = Agent(
    role="You are a helpful assistant.",
    model={"model": "gpt-4o-mini", "api_key": os.environ["OPENAI_API_KEY"]},
    memory={
        "type":       "redis",
        "connection": "redis://localhost:6379",
    },
)
```

Pass `session_id` in request metadata to persist history across turns:

```bash
curl -X POST http://localhost:8000 \
  -d '{"jsonrpc":"2.0","id":1,"method":"tasks/send","params":{"id":"t1","metadata":{"session_id":"user-123"},"message":{"role":"user","parts":[{"type":"text","text":"My name is Alice"}]}}}'
```

### With MCP server

```python
agent = Agent(
    role="You are a file assistant.",
    model={"model": "gpt-4o-mini", "api_key": os.environ["OPENAI_API_KEY"]},
    mcps=[{
        "type":    "stdio",
        "command": "npx",
        "args":    ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
    }],
)
```

## What's in the SDK

| Export | Type | Description |
|--------|------|-------------|
| `Agent` | Class | Main developer-facing class — wires provider, tools, memory, MCP |
| `AgentProtocol` | Protocol | Universal agent contract — implement `run()` |
| `ToolProtocol` | Protocol | Tool contract — implement `schema()` + `call()` |
| `AgentInput` | Model | Input to every agent invocation |
| `AgentOutput` | Model | Output chunk yielded by agents |
| `Message` | Model | Conversation history entry |
| `ToolCall` | Model | Tool invocation request |
| `ToolSchema` | Model | Tool JSON Schema description |
| `ModelConfig` | TypedDict | Provider + credentials config |
| `MemoryConfig` | TypedDict | Redis memory config |
| `MCPConfig` | TypedDict | MCP server connection config |
| `DataConfig` | TypedDict | RAG config (reserved) |
| `ToolWrapper` | Class | Wraps any callable as a `ToolProtocol` |
| `@tool` | Decorator | Function → `ToolWrapper` with auto-generated schema |
| `RawAdapter` | Class | **Deprecated** — use `Agent()` instead |

## @tool decorator

Plain functions passed to `tools=` are auto-wrapped. Use `@tool` when you want an explicit name or description:

```python
from agentinc.sdk import tool, ToolCall

@tool(name="add", description="Adds two numbers")
def add(a: float, b: float) -> str:
    return str(a + b)

result = await add.call(ToolCall(id="1", name="add", arguments={"a": 3, "b": 4}))
# "7.0"
```

## AgentProtocol — direct implementation

For framework integrations (LangChain, CrewAI) that manage their own LLM calls, implement `AgentProtocol` directly:

```python
from agentinc.sdk import AgentInput, AgentOutput, AgentProtocol
from agentinc.sdk.serve import serve

class MyAgent:
    async def run(self, input: AgentInput):
        yield AgentOutput(content=f"Got: {input.message}", done=True)

assert isinstance(MyAgent(), AgentProtocol)  # passes
serve(MyAgent(), name="my-agent", port=8000)
```

## Package extras

| Extra | Installs | Use for |
|-------|----------|---------|
| `openai` | `openai>=1.0` | OpenAI + any OpenAI-compatible endpoint |
| `anthropic` | `anthropic>=0.25` | Anthropic Claude models |
| `gemini` | `google-genai>=1.0` | Google Gemini models |
| `memory` | `redis>=5.0` | Redis-backed session memory |
| `mcp` | `mcp>=1.0` | MCP server connections |
| `serve` | fastapi, uvicorn, sse-starlette | A2A HTTP server |
| `all` | all of the above | Full install |

## Examples

See [`examples/`](examples/) for complete runnable agents:

| File | Description |
|------|-------------|
| [echo_agent.py](examples/echo_agent.py) | Minimal A2A agent (no LLM) |
| [streaming_agent.py](examples/streaming_agent.py) | SSE streaming |
| [tool_agent.py](examples/tool_agent.py) | `@tool` decorator demo |
| [openai_agent.py](examples/openai_agent.py) | OpenAI GPT-4o-mini with tools |
| [anthropic_agent.py](examples/anthropic_agent.py) | Anthropic Claude |
| [langchain_agent.py](examples/langchain_agent.py) | LangChain via AgentProtocol |
| [crewai_agent.py](examples/crewai_agent.py) | CrewAI via AgentProtocol |
| [agent_with_tools.py](examples/agent_with_tools.py) | Multi-tool agent |
| [memory_agent.py](examples/memory_agent.py) | Redis-backed session memory |
| [mcp_agent.py](examples/mcp_agent.py) | MCP filesystem server |
| [rag_agent.py](examples/rag_agent.py) | RAG with LightRAG |

## Requirements

- Python 3.12+
- `pydantic >= 2.7`
- Provider extras: `[openai]`, `[anthropic]`, `[gemini]`
- `[serve]` extra: `fastapi`, `uvicorn`, `sse-starlette`
- `[memory]` extra: `redis`
- `[mcp]` extra: `mcp`

## License

Apache 2.0 — see [LICENSE](LICENSE) for details.
