Increment version to 0.0.78 in pyproject.toml, add API dependencies…#474
Increment version to 0.0.78 in pyproject.toml, add API dependencies…#474MervinPraison merged 1 commit intomainfrom
pyproject.toml, add API dependencies…#474Conversation
… for FastAPI and Uvicorn, and implement HTTP API launch functionality in `agent.py` for enhanced agent interaction.
✅ Deploy Preview for praisonai canceled.
|
|
Caution Review failedThe pull request is closed. WalkthroughThis update introduces new example scripts demonstrating agent creation and HTTP API launching using the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant FastAPI Server
participant Agent
participant Tool (optional)
Client->>FastAPI Server: POST /{agent_path} with query
FastAPI Server->>Agent: chat(query)
alt Agent uses tool
Agent->>Tool (MCP/SSE): fetch external data
Tool (MCP/SSE)-->>Agent: return data
end
Agent-->>FastAPI Server: response
FastAPI Server-->>Client: JSON response
Suggested labels
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Hello @MervinPraison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request focuses on enhancing the PraisonAI agents by introducing HTTP API functionality. It increments the version to 0.0.78, adds FastAPI and Uvicorn as dependencies, and implements the launch method in agent.py to expose agents as API endpoints. The changes include adding new example scripts and modifying the pyproject.toml and uv.lock files to reflect the new dependencies and version.
Highlights
- API Launch Functionality: The core addition is the
launchmethod inagent.py, which allows agents to be exposed as HTTP API endpoints using FastAPI and Uvicorn. This includes handling queries via POST requests and managing server startup and shutdown. - Dependency Management: The
pyproject.tomlanduv.lockfiles are updated to includefastapianduvicornas dependencies under theapiextra, ensuring that the necessary packages are installed for the API functionality. - Example Scripts: New example scripts (
simple-api.py,simple-api-mcp.py, andmulti-agent-api.py) are added to demonstrate how to launch agents as APIs, showcasing different configurations and use cases.
Changelog
Click here to see the changelog
- examples/mcp/mcp-sse-weather.py
- Added a new example script demonstrating how to use an agent with MCP (Message Communication Protocol) and SSE (Server-Sent Events) for weather information, using
AgentandMCPfrompraisonaiagentsand starting the agent with a weather query.
- Added a new example script demonstrating how to use an agent with MCP (Message Communication Protocol) and SSE (Server-Sent Events) for weather information, using
- src/praisonai-agents/multi-agent-api.py
- Added a new example script demonstrating how to launch multiple agents as HTTP API endpoints, including weather, stock market, and travel agents, each with specific instructions and using the
launchmethod with blocking and non-blocking options.
- Added a new example script demonstrating how to launch multiple agents as HTTP API endpoints, including weather, stock market, and travel agents, each with specific instructions and using the
- src/praisonai-agents/praisonaiagents/agent/agent.py
- Added lazy loading for FastAPI dependencies to avoid unnecessary imports.
- Introduced shared variables (
_shared_app,_server_started,_registered_agents) for managing the API server. - Implemented the
launchmethod to expose agents as HTTP API endpoints, including handling API requests, managing server startup, and handling potential dependency import errors. - Added input validation and error handling for agent queries.
- Implemented path conflict resolution for multiple agents using the same path.
- src/praisonai-agents/pyproject.toml
- Incremented the package version from 0.0.77 to 0.0.78.
- Added
fastapianduvicornas dependencies under theapiextra. - Included the
apiextra in theallextra.
- src/praisonai-agents/simple-api-mcp.py
- Added a new example script demonstrating how to launch an agent with MCP as an HTTP API endpoint, using
AgentandMCPfrompraisonaiagentsand launching the agent on a specified path and port.
- Added a new example script demonstrating how to launch an agent with MCP as an HTTP API endpoint, using
- src/praisonai-agents/simple-api.py
- Added a new example script demonstrating how to launch a simple agent as an HTTP API endpoint, using
Agentfrompraisonaiagentsand launching the agent on a specified path and port.
- Added a new example script demonstrating how to launch a simple agent as an HTTP API endpoint, using
- src/praisonai-agents/uv.lock
- Incremented the package version from 0.0.77 to 0.0.78.
- Added
fastapianduvicornas dependencies under theapiextra. - Included
fastapianduvicornin theallextra. - Added dependency specifiers for
fastapianduvicornwith markers for theapiextra.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
An agent's API,
FastAPI's quick reply,
Uvicorn takes flight.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
The pull request introduces a new launch method to the Agent class, enabling agents to be exposed as HTTP API endpoints using FastAPI and Uvicorn. This enhancement provides a convenient way to interact with agents programmatically. The implementation includes lazy loading of dependencies, path conflict resolution, and support for both blocking and non-blocking server execution. Overall, this is a valuable addition to the library. However, there are some areas that could be improved for clarity, maintainability, and error handling.
Summary of Findings
- Error Handling: The error handling in the
launchmethod could be improved by raising exceptions instead of just printing to the console. This would allow calling code to handle errors more gracefully. - Path Conflict Resolution: The logic for handling path conflicts could be improved. Instead of just modifying the path, consider checking if the modified path is also registered or generating a completely random path.
- Asynchronous Compatibility: Consider using
asyncio.sleepinstead oftime.sleepto avoid blocking the event loop.
Merge Readiness
The pull request introduces a valuable feature for exposing agents as HTTP API endpoints. However, I recommend addressing the error handling and path conflict resolution issues before merging. Additionally, consider using asyncio.sleep instead of time.sleep for better asynchronous compatibility. I am unable to approve this pull request, and recommend that others review and approve this code before merging.
Increment version to 0.0.78 in `pyproject.toml`, add API dependencies…
… for FastAPI and Uvicorn, and implement HTTP API launch functionality in
agent.pyfor enhanced agent interaction.Summary by CodeRabbit
New Features
Chores