Metadata-Version: 2.4
Name: tfy_assistant_framework
Version: 0.1.0rc1
Summary: Framework for building AI assistants with streaming updates and user interactions
Project-URL: Homepage, https://github.com/truefoundry/tfy_assistant_framework
Project-URL: Repository, https://github.com/truefoundry/tfy_assistant_framework
Requires-Python: >=3.12
Requires-Dist: aiohttp<4.0.0,>=3.11.11
Requires-Dist: fastapi<1.0.0,>=0.115.6
Requires-Dist: httpx<1.0.0,>=0.28.1
Requires-Dist: logfire<4.0.0,>=3.4.0
Requires-Dist: nats-py[nkeys]<3.0.0,>=2.9.0
Requires-Dist: openai<2.0.0,>=1.58.1
Requires-Dist: pydantic-settings<3.0.0,>=2.7.0
Requires-Dist: pydantic<3.0.0,>=2.10.4
Requires-Dist: python-dotenv<2.0.0,>=1.0.1
Requires-Dist: rich<14.0.0,>=13.9.4
Requires-Dist: uvicorn<1.0.0,>=0.27.1
Description-Content-Type: text/markdown

# Tfy Assistant Framework

## Overview

The Tfy Assistant Framework is a framework for building AI assistants with streaming updates and user interactions.

## Installation

```bash
pip install tfy-assistant-framework
```

## Usage

Simple chat assistant:
```python
from tfy_assistant_framework.swarm import Agent, client

class Chat(Agent[Any]): ...

chat_agent = Chat(
    instructions="Chat with the user",
)

async def run_chat_assistant() -> None:
    async for agent_run in client.run(agent=chat_agent, messages=[], interactive=True):
        agent_run.debug_log()
```

This can be run in console directly to chat with the assistant. To serve the assistant via FastAPI,

```python
js: JetStreamContext
assistant_serve = AssistantServe()

@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
    global js
    async with nats_connection() as (nc, js_):
        js = js_
        async with assistant_serve.init(nc=nc, app=app):
            yield

app = FastAPI(
    title="LLM Assistants Server",
    lifespan=lifespan,
    docs_url="/",
)

@app.post("/assistants/chat/task")
async def chat_task() -> CreateAssistantTaskRunResult:
    task_id = uuid.uuid4().hex
    return await assistant_serve.create_assistant_task(
        task_id=task_id,
        assistant_awaitable=run_chat_assistant(),
        assistant_update_sink=NATSAssistantUpdateSink(task_id=task_id, js=js),
    )

@app.post("/tasks/{task_id}/message")
async def send_message_to_assistant_task(
    task_id: str,
    message: PostAssistantTaskMessage,
) -> Response:
    return await assistant_serve.send_message_to_assistant_task(task_id, message)
```


For more examples, see the [examples](https://github.com/truefoundry/tfy_assistant_framework/tree/main/examples) directory.
