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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- bugfix/28-cannot-auth-tools-list (2024-11-30)

### Changed
- feat/290-api-as-a-tool (2025-05-06)
- feat/288-add-contact-create-to-oauth (2025-05-05)
- feat/287-limit-input-buttons (2025-05-04)
- feat/281-public-server-display-on-landing (2025-05-03)
Expand Down
9 changes: 9 additions & 0 deletions backend/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
"console": "integratedTerminal",
"justMyCode": false,
"envFile": "${workspaceFolder}/.env.test"
},
{
"name": "Python: Run src.tools.api-new",
"type": "debugpy",
"request": "launch",
"module": "src.tools.api_new",
"console": "integratedTerminal",
"justMyCode": false,
"envFile": "${workspaceFolder}/.env"
}
]
}
2 changes: 1 addition & 1 deletion backend/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
from src.models import Base
from src.services.db import Base
from src.constants import DB_URI

config = context.config
Expand Down
48 changes: 48 additions & 0 deletions backend/migrations/versions/0010_add_tools_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Add tools table

Revision ID: 0010
Revises: 0009
Create Date: 2025-05-09T00:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = '0010'
down_revision: Union[str, None] = '0009'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

def upgrade() -> None:
# Create tools table
op.create_table(
'tools',
sa.Column('id', postgresql.UUID(as_uuid=True), server_default=sa.text('gen_random_uuid()'), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.Column('url', sa.String(), nullable=True),
sa.Column('spec', sa.JSON(), nullable=True),
sa.Column('headers', sa.JSON(), nullable=True),
sa.Column('tags', sa.JSON(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)

# Create indexes
op.create_index('tools_user_id_idx', 'tools', ['user_id'], unique=False)
op.create_index('tools_name_idx', 'tools', ['name'], unique=False)
op.create_index('tools_url_idx', 'tools', ['url'], unique=False)
# op.create_index('tools_tags_idx', 'tools', ['tags'], unique=False)
# Create unique index on name and user_id
op.create_index('tools_name_user_id_idx', 'tools', ['name', 'user_id'], unique=True)

def downgrade() -> None:
# Drop tools table
op.drop_table('tools')
9 changes: 5 additions & 4 deletions backend/src/controllers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
from src.repos.user_repo import UserRepo
from src.utils.logger import logger
from src.utils.a2a import process_a2a_streaming, process_a2a

from src.repos.tool_repo import ToolRepo

class AgentController:
def __init__(self, db: AsyncSession, user_id: str = None, agent_id: str = None): # type: ignore
self.user_repo = UserRepo(db=db, user_id=user_id)
self.agent_repo = AgentRepo(db=db, user_id=user_id)
self.tool_repo = ToolRepo(db=db, user_id=user_id)
self.agent_id = agent_id

async def anew_thread(
Expand All @@ -41,7 +42,7 @@ async def anew_thread(
# else:
# return await process_a2a(new_thread, thread_id)

agent = Agent(config=config, user_repo=self.user_repo)
agent = Agent(config=config, user_repo=self.user_repo, tool_repo=self.tool_repo)
await agent.abuilder(tools=new_thread.tools,
model_name=new_thread.model,
mcp=new_thread.mcp,
Expand Down Expand Up @@ -89,7 +90,7 @@ async def aexisting_thread(
# else:
# return await process_a2a(existing_thread, thread_id)

agent = Agent(config=config, user_repo=self.user_repo)
agent = Agent(config=config, user_repo=self.user_repo, tool_repo=self.tool_repo)
await agent.abuilder(tools=existing_thread.tools,
model_name=existing_thread.model,
mcp=existing_thread.mcp,
Expand Down Expand Up @@ -129,7 +130,7 @@ async def async_agent_thread(
"system": settings.get("system") or None
}

agent = Agent(config=config, user_repo=self.user_repo)
agent = Agent(config=config, user_repo=self.user_repo, tool_repo=self.tool_repo)
await agent.abuilder(tools=settings.get("tools", []), model_name=settings.get("model"), mcp=settings.get("mcp", None))
if thread_id:
messages = agent.existing_thread(query, settings.get("images"))
Expand Down
22 changes: 21 additions & 1 deletion backend/src/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,24 @@ class SearchKwargs(dict):
k: int = 3
fetch_k: int = 2
lambda_mult: float = 0.5
filter: str = None
filter: str = None

class AgentTool(BaseModel):
name: str
description: str
url: str
spec: dict | str = None
headers: dict = None
tags: list[str] = None

model_config = {
"json_schema_extra": {"example": {"name": "tool1", "description": "tool1 description", "url": "http://localhost:8050/openapi.json", "spec": None, "headers": {}, "tags": ["tag1", "tag2"]}}
}

class AgentToolList(BaseModel):
tools: list[AgentTool] = Field(...)

model_config = {
"json_schema_extra": {"example": {"tools": [{"name": "tool1", "description": "tool1 description", "url": "https://tool1.com", "spec": None, "headers": {}, "tags": ["tag1", "tag2"]}]}}
}

Loading
Loading