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

Problem with message_files (Files were not found) #206

Closed
tg-bomze opened this issue Dec 24, 2024 · 2 comments
Closed

Problem with message_files (Files were not found) #206

tg-bomze opened this issue Dec 24, 2024 · 2 comments

Comments

@tg-bomze
Copy link

I'm using the modified code from the notebook os_models_with_astra_assistants_api.ipynb. In my pipeline, I don't need any files to process remotely (all my tools are geared towards running utilities in Ubuntu and local files), so I commented out the line:

gen = agency.get_completion(
            message=original_message,
            # message_files=[],
            recipient_agent=recipient_agent,
            yield_messages=True,
        )

Actually, I have tried specifying both None and [] in message_files. In this case, the agent in gradio writes:

image

And there's an error in the logs:

File "/home/denis/TestAgency/agency.py", line 120, in bot 
    for bot_message in gen:
  File "/home/denis/venv/lib/python3.10/site-packages/agency_swarm/threads/thread.py", line 271, in get_completion
    output = yield from handle_output(tool_call, output)
  File "/home/denis/venv/lib/python3.10/site-packages/agency_swarm/threads/thread.py", line 187, in handle_output
    item = next(output)
  File "/home/denis/venv/lib/python3.10/site-packages/agency_swarm/threads/thread.py", line 151, in get_completion
    message_obj = self.create_message(
  File "/home/denis/venv/lib/python3.10/site-packages/agency_swarm/threads/thread.py", line 589, in create_message
    return self.client.beta.threads.messages.create(
  File "/home/denis/venv/lib/python3.10/site-packages/openai/resources/beta/threads/messages.py", line 99, in create
    return self._post(
  File "/home/denis/venv/lib/python3.10/site-packages/openai/_base_client.py", line 1280, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
  File "/home/denis/venv/lib/python3.10/site-packages/openai/_base_client.py", line 957, in request
    return self._request(
  File "/home/denis/venv/lib/python3.10/site-packages/openai/_base_client.py", line 1061, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: Error code: 404 - {'error': {'message': 'Files [file-1] were not found', 'type': 'invalid_request_error', 'param': None, 'code': None}

What can cause this problem? How do I prevent remote files from being used?

Libraries versions:

  • agency-swarm==0.4.2
  • openai==1.58.1
@ArtemShatokhin
Copy link
Contributor

ArtemShatokhin commented Jan 16, 2025

Hi @tg-bomze, this error is the result of agent's hallucinations, where it tries to attach non-existing files.
The SendMessage tool is built just like any other tool, so the agent itself defines its input, along with file ids it wants to pass to other agents. Sometimes these hallucinations can be caused by the abundance of files attached to an agent or somewhat vague instructions.
This can be typically solved by specifying the purpose of every file attached to an agent or providing clear instructions which files should be passed to other agents and when.
Another possible reason is that agents don't have the file ids of the files in their own database initially and you first need to ask them to use file retrieval to get it with a prompt like provide a file id of the example.txt file. It should start with "file-". Otherwise it might just use a placeholder, like it did in your example.
Considering in your case you want to get rid of files passing entirely, you can create a modified version of SendMessage tool that does not attach file id to messages and set agencie's send_message_tool_class to use your version instead, like so:

from agency_swarm.tools.send_message.SendMessageBase import SendMessageBase
class CustomSendMessage(SendMessageBase):
    """Use this tool to facilitate direct, synchronous communication between specialized agents within your agency. When you send a message using this tool, you receive a response exclusively from the designated recipient agent. To continue the dialogue, invoke this tool again with the desired recipient agent and your follow-up message. Remember, communication here is synchronous; the recipient agent won't perform any tasks post-response. You are responsible for relaying the recipient agent's responses back to the user, as the user does not have direct access to these replies. Keep engaging with the tool for continuous interaction until the task is fully resolved. Do not send more than 1 message to the same recipient agent at the same time."""
    my_primary_instructions: str = Field(
        ..., 
        description=(
            "Please repeat your primary instructions step-by-step, including both completed "
            "and the following next steps that you need to perform. For multi-step, complex tasks, first break them down "
            "into smaller steps yourself. Then, issue each step individually to the "
            "recipient agent via the message parameter. Each identified step should be "
            "sent in a separate message. Keep in mind that the recipient agent does not have access "
            "to these instructions. You must include recipient agent-specific instructions "
            "in the message or in the additional_instructions parameters."
        )
    )
    message: str = Field(
        ..., 
        description="Specify the task required for the recipient agent to complete. Focus on clarifying what the task entails, rather than providing exact instructions. Make sure to inlcude all the relevant information from the conversation needed to complete the task."
    )
    additional_agent_instructions: Optional[str] = Field(
        default=None,
        description="Additional context or instructions from the conversation needed by the recipient agent to complete the task."
    )
    
    def run(self):
        return self._get_completion(message=self.message,
                                    additional_instructions=self.additional_instructions)


agency = Agency(
    [
        test_agent

    ],
    shared_instructions="./agency_manifesto.md",
    send_message_tool_class=CustomSendMessage,
)

Keep in mind, however, that in this case, all agents within agency would not be able to pass file ids between each other.
You can find the original SendMessage tool here, in case you want to compare the changes: https://github.com/VRSEN/agency-swarm/blob/main/agency_swarm/tools/send_message/SendMessage.py

@tg-bomze
Copy link
Author

Thank you very much. It worked!

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