Skip to content
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

[backend] agent tool metadata db #309

Merged
merged 5 commits into from
Jun 28, 2024
Merged

[backend] agent tool metadata db #309

merged 5 commits into from
Jun 28, 2024

Conversation

scott-cohere
Copy link
Contributor

@scott-cohere scott-cohere commented Jun 27, 2024

  • create new table
  • create tool metadata entries on agent creation
  • new crud endpoints for the table
  • unit test

AI Description

This PR introduces the AgentToolMetadata model and its associated CRUD operations, tests, and API endpoints.

Code Changes:

  • Added a new AgentToolMetadata model in src/backend/database_models/agent_tool_metadata.py to represent agent tool metadata.
  • Modified src/backend/routers/agent.py to include endpoints for creating, listing, updating, and deleting agent tool metadata.
  • Added new functions in src/backend/crud/agent_tool_metadata.py for CRUD operations on AgentToolMetadata.
  • Updated src/backend/chat/custom/custom.py to include agent_id in the call_tools function.
  • Added tests for AgentToolMetadata CRUD operations in src/backend/tests/routers/test_agent.py and src/backend/tests/crud/test_agent_tool_metadata.py.
  • Added a new AgentToolMetadataFactory in src/backend/tests/factories/agent_tool_metadata.py for generating test data.
  • Updated imports in multiple files to include the new AgentToolMetadata model and related functions.

Summary:
The main purpose of this PR is to add support for managing agent tool metadata, including creating, updating, listing, and deleting metadata associated with specific agents. This enhancement provides a structured way to store and retrieve metadata related to agent tools, improving the flexibility and maintainability of the system.

@scott-cohere scott-cohere marked this pull request as ready for review June 27, 2024 18:20
@giannis2two
Copy link
Contributor

giannis2two commented Jun 27, 2024

As discussed, alternative design to be more generalized for more tools

class AgentToolArtifact(Base):
    __tablename__ = "agent_tool_artifact"

    user_id: Mapped[str] = mapped_column(Text, nullable=False)
    agent_id: Mapped[str] = mapped_column(
        ForeignKey("agents.id", ondelete="CASCADE"), nullable=False
    )
    tool_name: Mapped[str] = mapped_column(Text, nullable=False)
    artifact_id: Mapped[str] = mapped_column(Text, nullable=False)
    type: Mapped[str] = mapped_column(Text, nullable=False)

    __table_args__ = (
        UniqueConstraint(
            "user_id", "agent_id", "tool_name", "artifact_id", name="_user_agent_tool_name_artifact_id_uc"
        ),
    )

Then you can do the following

  • Create a new entry for each folder/file/url
    • One to many (agent to artifacts)
  • With type you can define an arbitrary string that the client (backend) can use to conditionally parse
    • If folder and google_drive then I know what to do
    • If url and web_search then I know what to do

@scott-cohere
Copy link
Contributor Author

@giannis2two
Slight deviation from proposed payload for passing in the artifacts, it is now this:

        "tools_metadata": [
            {
                "tool_name": ToolName.Google_Drive,
                "artifacts": ["folder1", "folder2"],
                "type": "folder_ids",
            },
            {
                "tool_name": ToolName.Google_Drive,
                "artifacts": ["file1", "file2"],
                "type": "file_ids",
            },
        ],
   

This plays better with the DB schema and a lot easier to parse. I don't imagine it would be a huge issue to parse like this on the client side.

@scott-cohere scott-cohere changed the title [backend] tool metadata db [backend] agent tool metadata db Jun 28, 2024
Copy link
Contributor

@giannis2two giannis2two left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High level looks great! 🥳

src/backend/routers/agent.py Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 96.28253% with 10 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@14f5b38). Learn more about missing BASE report.

Files Patch % Lines
src/backend/routers/agent.py 81.63% 9 Missing ⚠️
src/backend/alembic/versions/2d766d30a3d2_.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #309   +/-   ##
=======================================
  Coverage        ?   86.13%           
=======================================
  Files           ?      172           
  Lines           ?     6421           
  Branches        ?        0           
=======================================
  Hits            ?     5531           
  Misses          ?      890           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/backend/routers/agent.py Show resolved Hide resolved
src/interfaces/coral_web/package.json Show resolved Hide resolved
@lusmoura lusmoura merged commit b064489 into main Jun 28, 2024
3 checks passed
@lusmoura lusmoura deleted the scott/tools-table-main branch June 28, 2024 12:40
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.

4 participants