datastax / astra-assistants-api

Drop in replacement for the OpenAI Assistants API
Apache License 2.0
142 stars 17 forks source link

Tool Usage Blocked After Message Output #56

Closed VRSEN closed 2 months ago

VRSEN commented 3 months ago

Description

When using the Astra Assistants API, there is an issue where the execution stops if the assistant outputs a message before using a tool. In the OpenAI Assistants API, the agent can output a message and then use a tool subsequently. However, with Astra Assistants, if the agent outputs any message, the execution stops and prevents further tool usage. The execution works correctly if the agent uses tools before outputting any message.

Steps to Reproduce

  1. Create an assistant using the Astra Assistants API.
  2. Instruct the assistant to output a message and then use a tool: "You must say 'I am using test tool' and then use test tool in this exact order in a single message. Do not use test tool before you said you are using it."
  3. Observe that the execution stops after the message is outputted, and the tool is not used.

Expected Behavior

The assistant should be able to output a message and then use a tool seamlessly, as it works in the OpenAI Assistants API.

Actual Behavior

The execution stops after the assistant outputs a message, preventing any subsequent tool usage.

Example

from openai import OpenAI
from astra_assistants import patch
from agency_swarm import Agent, Agency, set_openai_client
from dotenv import load_dotenv
from agency_swarm.tools import BaseTool

load_dotenv('../.env')

client = patch(OpenAI())

set_openai_client(client)

class TestTool(BaseTool):
    """
    A simple tool that prints 'test'.
    """

    def run(self):
        """
        This method prints the word 'test'.
        """
        print("test")
        return "Test has been printed."

ceo = Agent(name="Test Agent",
            description="Test Agent for testing purposes",
            instructions="You must say 'I am using test tool' and then use test tool in the same message.",
            # model="perplexity/llama-3-8b-instruct",
            # model="anthropic/claude-3-haiku-20240307",
            # model="groq/mixtral-8x7b-32768",
            model="gpt-4o",
            # files_folder="./examples/python/agency-swarm/files",
            temperature=0,
            tools=[TestTool])

agency = Agency([ceo])

completion = agency.get_completion("Please say 'I am using test tool' and ONLY THEN use test tool.")
print(completion)

Environment

Additional Information

phact commented 3 months ago

Fixed in v0.2.14 Shipped to dockerhub and to the service

phact commented 2 months ago

Closing as fixed