Skip to main content

Framework for building AI assistants with streaming updates and user interactions

Project description

Tfy Assistant Framework

Overview

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

Installation

pip install tfy-assistant-framework

Usage

Simple chat assistant:

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,

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 directory.

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

tfy_assistant_framework-0.1.1rc1.tar.gz (73.5 kB view details)

Uploaded Source

Built Distribution

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

tfy_assistant_framework-0.1.1rc1-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file tfy_assistant_framework-0.1.1rc1.tar.gz.

File metadata

File hashes

Hashes for tfy_assistant_framework-0.1.1rc1.tar.gz
Algorithm Hash digest
SHA256 f6d23ccc7954101bedebd084b857837273f7648370d770f903a217d53f587a34
MD5 2cf02f8efc8433dada66e86efe56aaa5
BLAKE2b-256 4bdb3c541419fa1bb071e0ab19d9a0976ce68c53b154e44fb8ad2e3e192e327a

See more details on using hashes here.

File details

Details for the file tfy_assistant_framework-0.1.1rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for tfy_assistant_framework-0.1.1rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e983b8a49ab0b8aaf9a9cfd4fbd929666664698f92316ec933f06d58a46a947
MD5 ba996bd7d02bbabc67db4e79430aa129
BLAKE2b-256 60e84d2c0985f647d09cc014bbec2ddab1bc1a8b96edaabb01ef5901b4d8c8ed

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