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

Fix Agents to support code and rag simultaneously #908

Merged
merged 4 commits into from
Jan 31, 2025
Merged

Conversation

hardikjshah
Copy link
Contributor

What does this PR do?

Fixes a bug where agents were not working when both rag and code-interpreter were added as tools.

Test Plan

Added a new client_sdk test which tests for this scenario

LLAMA_STACK_CONFIG=together pytest -s -v  tests/client-sdk -k 'test_rag_and_code_agent'

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 30, 2025
@@ -476,9 +476,6 @@ async def _run(
)
span.set_attribute("output", retrieved_context)
span.set_attribute("tool_name", MEMORY_QUERY_TOOL)
if retrieved_context:
last_message = input_messages[-1]
last_message.context = retrieved_context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there another place where we set the context for RAG?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah how does RAG even work if you don't do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, all tests were passing for RAG but then i realized there was nothing getting added to the context.
I tested this change and now can see RAG work properly.


# append retrieved_context to the last user message
for message in input_messages[::-1]:
if isinstance(message, UserMessage):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other message type could this be if it's triggering RAG?

Separately curious why for RAG results we use .context but for other tool execs we do 708 input_messages = input_messages + [message, result_message]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ehhuang I think @hardikjshah did this so you could identify which message you added context to and then in the next turn get rid of it. we needed to keep only one context around as the turns proceeded.

I really think we should nuke that .context field completely and manage whatever state we need to manage completely within agent_instance.py (and ensure the invariant above)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other message type could this be if it's triggering RAG?

That was the original bug , where if both code and rag are enabled, we end up with a ToolResponseMessage coming from the code_interpreter side (check out def handle_documents)

And it was erroring since ToolResponseMessage does not have any attr context.

I agree that we should find a better solution to context. May be RAG responses are also passed in the ToolResponseMessage like all other tools. Although outside the scope of this PR.

Copy link
Contributor

@ashwinb ashwinb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lg! Agree with killing .context completely.

@hardikjshah hardikjshah merged commit 97eb3ee into main Jan 31, 2025
2 checks passed
@hardikjshah hardikjshah deleted the agent_fix branch January 31, 2025 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants