Skip to content

Commit

Permalink
Remove title key from input JSON schema of AgentTool. #629
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukinobu-Mine committed Dec 12, 2024
1 parent 4ec0465 commit dd979e0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion backend/app/agents/tools/agent_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from app.repositories.models.custom_bot import BotModel
from app.routes.schemas.conversation import type_model_name
from pydantic import BaseModel, JsonValue
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaValue
from mypy_boto3_bedrock_runtime.type_defs import (
ToolSpecificationTypeDef,
)
Expand Down Expand Up @@ -49,6 +50,16 @@ class InvalidToolError(Exception):
pass


class RemoveTitle(GenerateJsonSchema):
def field_title_should_be_set(self, schema) -> bool:
return False

def generate(self, schema, mode="validation") -> JsonSchemaValue:
value = super().generate(schema, mode)
del value["title"]
return value


class AgentTool(Generic[T]):
def __init__(
self,
Expand All @@ -71,7 +82,7 @@ def __init__(

def _generate_input_schema(self) -> dict[str, Any]:
"""Converts the Pydantic model to a JSON schema."""
return self.args_schema.model_json_schema()
return self.args_schema.model_json_schema(schema_generator=RemoveTitle)

def to_converse_spec(self) -> ToolSpecificationTypeDef:
return ToolSpecificationTypeDef(
Expand Down

0 comments on commit dd979e0

Please sign in to comment.