Skip to content

Tool use breaks model #8

@torphix

Description

@torphix

Hi, I am able to get the sample code running well with a custom system prompt.
However when i pass in tools like so:

class AgentTools(ToolContext):
    def __init__(self) -> None:
        super().__init__()

        # Add new addition tool
        self.register_function(
            name="add_numbers",
            description="Adds two numbers together and returns the sum",
            parameters={
                "type": "object",
                "properties": {
                    "number1": {
                        "type": "number",
                        "description": "First number to add",
                    },
                    "number2": {
                        "type": "number",
                        "description": "Second number to add",
                    },
                },
                "required": ["number1", "number2"],
            },
            fn=self._add_numbers_async,
        )

    async def _add_numbers_async(
        self,
        number1: float,
        number2: float,
    ) -> dict[str, Any]:
        """
        Asynchronously adds two numbers together.
        Returns the result in a dictionary.
        """
        try:
            result = number1 + number2
            return {
                "status": "success",
                "message": f"Successfully added numbers: {number1} + {number2} = {result}",
                "data": {
                    "result": result,
                },
            }
        except Exception as e:
            logger.error(f"Error adding numbers: {str(e)}")
            return {
                "status": "error",
                "message": f"Failed to add numbers: {str(e)}",
            }
asyncio.run(
    RealtimeKitAgent.setup_and_run_agent(
        engine=RtcEngine(appid=engine_app_id, appcert=engine_app_cert),
        options=RtcOptions(
            channel_name=channel_name,
            uid=uid,
            sample_rate=PCM_SAMPLE_RATE,
            channels=PCM_CHANNELS,
            enable_pcm_dump=os.environ.get("WRITE_RTC_PCM", "false") == "true",
        ),
        inference_config=inference_config,
        tools=AgentTools(),
    )
)

I get an error message:
agent - WARNING - Unhandled message message=ErrorMessage(event_id='event_ARKsWqqhvlaU9mNLhvzy7', error=RealtimeError(type='invalid_request_error', message="Missing required parameter: 'session.tools[0].name'.", code='missing_required_parameter', param='session.tools[0].name', event_id='0e67ca30-a093-43d3-8200-b6e155c88bcb'), type='error')

and it seems as if the system prompt is no longer attended to (as the model starts speaking in Spanish with no reference to anything mentioned in the system prompt.

Am i doing something wrong in passing of the tools?
Note that when i remove the tools it works well with the system prompt.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions