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

Tool use breaks model #8

Closed
torphix opened this issue Nov 8, 2024 · 1 comment
Closed

Tool use breaks model #8

torphix opened this issue Nov 8, 2024 · 1 comment

Comments

@torphix
Copy link

torphix commented Nov 8, 2024

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

@plutoless
Copy link
Contributor

resolved in #11

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

No branches or pull requests

2 participants