Skip to content

FROM feat/290-api-as-a-tool TO development #293

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

Open
wants to merge 12 commits into
base: development
Choose a base branch
from

Conversation

ryaneggz
Copy link
Collaborator

@ryaneggz ryaneggz commented May 6, 2025

Closes #290

Summary by CodeRabbit

  • New Features
    • Introduced dynamic generation of OpenAPI-based tools, allowing users to interact with multiple REST APIs seamlessly.
    • Added support for creating tools for multiple remote agents, enabling broader agent interactions.
    • Added new API endpoints for listing and invoking tools, as well as querying MCP and A2A service information.
    • Added database support for managing tools, agents, revisions, servers, settings, threads, users, and tokens with enhanced serialization and slug generation.
    • Introduced tool management API endpoints for creating, listing, and invoking tools with user authentication.
  • Improvements
    • Enhanced agent builder to support dynamic naming and improved debug configuration.
    • Refactored agent-to-agent tool creation to support multiple agents dynamically.
    • Improved error logging during authentication token verification.
  • Chores
    • Updated changelog with new feature entry.
    • Added a new VSCode debug configuration for easier development and testing.
    • Configured automatic restart for PostgreSQL and pgAdmin services in Docker setup.
    • Modularized API routes for better organization and scalability.
    • Simplified model imports by restructuring model definitions into separate modules.

Copy link
Contributor

coderabbitai bot commented May 6, 2025

Walkthrough

The changes introduce a new dynamic API tool generation module, refactor A2A tool creation to support multiple agents, and update the agent utility to leverage these new capabilities. The agent builder now integrates both A2A and OpenAPI-derived tools. Additionally, a new VSCode debug configuration and a changelog entry for the new feature branch are added. The previous monolithic tool route is replaced by modular sub-routers for tool operations, including custom MCP and A2A info endpoints, tool creation, listing, and invocation. New database models and repositories for tools, agents, servers, settings, threads, and users are introduced, alongside refactoring of model imports.

Changes

File(s) Change Summary
Changelog.md Added a new entry in the "Changed" section for the "feat/290-api-as-a-tool" feature branch dated "2025-05-06".
backend/src/tools/a2a.py Refactored single-agent A2A tool function to a multi-agent factory (create_a2a_tools), generating a list of tools from agent configurations. Removed the single-tool export.
backend/src/tools/api.py Introduced a new module for dynamic OpenAPI spec generation, retrieval, and API tool creation. Includes utilities for schema inference, $ref resolution, dynamic Pydantic model creation, and tool generation from OpenAPI specs.
backend/src/utils/agent.py Updated imports, refactored A2A tool integration to use create_a2a_tools, added OpenAPI tool generation, and made the agent's name dynamic in the abuilder method. Added optional tool_repo parameter to Agent constructor and usage.
backend/.vscode/launch.json Added a new debug configuration for running src.tools.api_new with debugpy and environment variables from .env.
backend/src/routes/v0/init.py Added import and export of new router tool_custom.
backend/src/routes/v0/tool.py Deleted the entire file which contained tool-related endpoints for listing and invoking tools, and MCP/A2A info retrieval.
backend/src/routes/v0/tool/init.py Added new FastAPI router with endpoints for listing tools and invoking tools by ID, including user credential verification and error handling.
backend/src/routes/v0/tool/custom.py Added new FastAPI router with endpoints for MCP info and A2A agent card retrieval, including error handling and request validation; includes commented-out stub for A2A agent invocation.
backend/src/routes/v0/tool/create.py Added new POST endpoint for creating tools with user authentication and error handling.
backend/src/routes/v0/tool/invoke.py Added new POST endpoint for invoking tools by ID with argument validation, user authentication, and error handling.
backend/src/routes/v0/tool/list.py Added new GET endpoint for listing tools with optional user authentication and error handling.
backend/src/tools/sql.py Added a single blank line after an import; no functional changes.
docker-compose.yml Added restart: always policy to postgres and pgadmin services for automatic container restart.
backend/migrations/env.py Changed import of Base from src.models to src.services.db for Alembic migration metadata.
backend/migrations/versions/0010_add_tools_table.py Added migration to create tools table with columns, indexes, and foreign keys; includes upgrade and downgrade functions.
backend/src/entities/init.py Added Pydantic models AgentTool and AgentToolList defining tool schemas with examples.
backend/src/models/init.py Removed inline model definitions; replaced with imports and re-exports of models from separate files.
backend/src/models/agent.py Added ORM models for Agent, Revision, and Tool with fields, relationships, serialization, and slug generation.
backend/src/models/server.py Added ORM model Server with fields, relationships, serialization, and slug generation.
backend/src/models/setting.py Added ORM model Settings with fields, relationships, serialization, and slug generation.
backend/src/models/thread.py Added ORM model Thread with composite primary key, foreign keys, relationships, and serialization.
backend/src/models/user.py Added ORM models User, Token, and Pydantic model ProtectedUser with password hashing, encryption, and serialization utilities.
backend/src/repos/tool_repo.py Added ToolRepo class implementing async CRUD operations for tools with singleton pattern, combining user and static tools.
backend/src/services/db.py Added Base = sa.orm.declarative_base() as SQLAlchemy ORM base class.
backend/src/utils/auth.py Enhanced JWT error handling in verify_credentials to log errors.
backend/src/controllers/agent.py Added initialization of ToolRepo and passed it to Agent constructor in controller methods.
backend/src/tools/init.py Added import of BaseTool; updated dynamic_tools function to accept optional tool_selection parameter for filtering tools.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Agent
    participant A2A Tool Factory
    participant API Tool Generator
    participant Remote Agent
    participant API Endpoint

    User->>Agent: Request agent construction (abuilder)
    Agent->>A2A Tool Factory: create_a2a_tools(a2a_config)
    A2A Tool Factory->>Remote Agent: Prepare StructuredTool per agent config
    Agent->>API Tool Generator: generate_tools_from_openapi_spec(openapi_url)
    API Tool Generator->>API Endpoint: Fetch OpenAPI spec & endpoints
    API Tool Generator->>Agent: Return list of StructuredTools
    Agent->>User: Agent ready with A2A and API tools
Loading

Poem

🐰
New tools have hopped into our den,
APIs and agents—now more than ten!
With specs that grow and tools that spawn,
Our clever code just hops right on.
Debugging’s easy, docs are neat—
This rabbit’s work is quite a feat!

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between de28ce6 and 6c1ca23.

📒 Files selected for processing (1)
  • backend/src/tools/api.py (1 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Join our Discord community 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FEATURE: As a user, I'd like to be able to create a tool from an API endpoint
1 participant