-
-
Notifications
You must be signed in to change notification settings - Fork 437
Add FastAPI integration example #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Adds a straightforward example showing how to use Atomic Agents with FastAPI. Includes session management, RESTful endpoints, and proper cleanup patterns. Resolves #40 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Automated review by Greptile Greptile OverviewGreptile SummaryThis PR successfully adds a well-structured FastAPI integration example demonstrating multi-user, multi-session conversational AI with Atomic Agents. The implementation addresses issue #40 by providing an approachable starting point for developers. Key improvements from previous review iterations:
What this PR delivers:
Minor documentation issue:
The code follows Atomic Agents best practices from Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Client
participant FastAPI
participant SessionManager
participant AtomicAgent
participant OpenAI
Note over Client,FastAPI: Session Creation Flow
Client->>FastAPI: POST /users/{user_id}/sessions
FastAPI->>SessionManager: _generate_session_id()
SessionManager-->>FastAPI: session_id (UUID)
FastAPI->>SessionManager: Store in session_metadata
FastAPI-->>Client: SessionCreateResponse
Note over Client,OpenAI: Chat Flow (Non-Streaming)
Client->>FastAPI: POST /chat (ChatRequest)
FastAPI->>SessionManager: _add_message_to_history("user", message)
FastAPI->>SessionManager: get_or_create_agent(user_id, session_id)
SessionManager->>AtomicAgent: create_chat_agent() if new
SessionManager-->>FastAPI: agent instance
FastAPI->>AtomicAgent: agent.run(ChatRequest)
AtomicAgent->>OpenAI: API call with system prompt + history
OpenAI-->>AtomicAgent: ChatResponse
AtomicAgent-->>FastAPI: ChatResponse
FastAPI->>SessionManager: _add_message_to_history("assistant", response)
FastAPI-->>Client: ChatResponse
Note over Client,OpenAI: Chat Flow (Streaming)
Client->>FastAPI: POST /chat/stream (ChatRequest)
FastAPI->>SessionManager: _add_message_to_history("user", message)
FastAPI->>SessionManager: get_or_create_async_agent(user_id, session_id)
SessionManager->>AtomicAgent: create_async_chat_agent() if new
SessionManager-->>FastAPI: async agent instance
FastAPI->>AtomicAgent: agent.run_async_stream(ChatRequest)
loop Stream chunks
AtomicAgent->>OpenAI: Streaming API call
OpenAI-->>AtomicAgent: Response chunk
AtomicAgent-->>FastAPI: ChatResponse chunk
FastAPI-->>Client: SSE data event
end
FastAPI->>SessionManager: _add_message_to_history("assistant", full_response)
Note over Client,FastAPI: History & Session Management
Client->>FastAPI: GET /users/{user_id}/sessions/{session_id}/history
FastAPI->>SessionManager: Fetch from conversation_history
FastAPI-->>Client: ConversationHistory
Client->>FastAPI: DELETE /users/{user_id}/sessions/{session_id}
FastAPI->>SessionManager: Remove from sessions/async_sessions/metadata/history
FastAPI-->>Client: SessionDeleteResponse
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, 3 comments
Updates imports to use the correct paths and adds docstrings to schema classes as required by BaseIOSchema. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, 1 comment
- Add proper type parameters to AtomicAgent instantiation - Update README to match other examples' setup pattern - Remove .env.example (gitignored pattern) - Verified end-to-end functionality with actual API calls 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, no comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
22 files reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
22 files reviewed, no comments
This adds a simple FastAPI example to help developers get started with integrating Atomic Agents into their web APIs.
What's included
Why this approach
While we have the MCP-based FastAPI example which shows advanced usage, this provides a more approachable starting point for developers who just want to add conversational AI to their FastAPI apps.
The example uses the empty
fastapi-memory/directory that was already in the repo.Closes #40
🤖 Generated with Claude Code