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 user commands in terminal with function calling #4955

Merged
merged 11 commits into from
Nov 14, 2024
Merged

Conversation

enyst
Copy link
Collaborator

@enyst enyst commented Nov 12, 2024

End-user friendly description of the problem this fixes or functionality that this introduces

  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below
    Fix agent crash when terminal commands are sent and function calling is enabled

Give a summary of what the PR does, explaining any non-trivial design decisions

When function calling is enabled, the agent expected all CmdRunAction to be "tools", but if they were sent by the user in the terminal, they were not, they were regular command actions.

This PR proposes to convert them into Messages as usual pre-function calling. Since they have source 'user', same as the next observation, and potentially more (a user message in chat probably follows too), they all get added to the same Message with role='user' when sent to the LLM.

(Outdated now)
On a side note, the concatenation... worked too well, so much so that Claude felt the need to help the human:

Prompt:

----------

... # other stuff done by the agent

----------

pwd
OBSERVATION:
/workspace[Python Interpreter: /openhands/poetry/openhands-ai-5O4_aCHf-py3.12/bin/python]
openhands@openhands-workspace:/workspace $ 
[Command finished with exit code 0]
print 5
print 55
hi there

LLM response:

23:56:25 - openhands:INFO: agent_controller.py:513
ACTION
[Agent Controller 6368bb2f-c5b4-4dc0-aea9-a973fe1afbc0] CmdRunAction (source=None)
THOUGHT: I notice you're trying to type commands but they seem to be jumbled together. Let me help you with the proper command. If you want to see the current working directory, you can use:
COMMAND:
pwd

😅

Maybe we should insert some mini-separators?
Done.


Link of any specific issues this addresses
Fix #4783


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:98c8b26-nikolaik   --name openhands-app-98c8b26   docker.all-hands.dev/all-hands-ai/openhands:98c8b26

@enyst enyst requested a review from xingyaoww November 12, 2024 23:24
@diwu-sf
Copy link
Contributor

diwu-sf commented Nov 12, 2024

Awesome that you're fixing this, I was just about to file a bug on this exact problem.

What if the user bash messages are just never shown to the LLM?
I'm not sure how much value showing ad-hoc shell commands and outputs to LLM would help with the task.
E.g. user is just running git status in workspace to skim what files agent changed, etc..

@enyst
Copy link
Collaborator Author

enyst commented Nov 12, 2024

It's a good question, it could go either way. It happens in the same time with the task, and we know we need to tell the agent when the user is making modifications, rather than just looking. 🤔

Please take a look also at the slack discussion.

@diwu-sf
Copy link
Contributor

diwu-sf commented Nov 13, 2024

Yes, it could go either way, made a UX suggestion to just have a checkbox on top of the terminal tab to let user decide whether his commands should be shown to the LLM

@enyst
Copy link
Collaborator Author

enyst commented Nov 13, 2024

Currently:

----------

COMMAND:
pwd
OBSERVATION:
/workspace
[Python Interpreter: /openhands/poetry/openhands-ai-5O4_aCHf-py3.12/bin/python]
openhands@openhands-workspace:/workspace $ 
[Command finished with exit code 0]
print 99 ?

----------

I'll help you print the number 99 using Python in the IPython environment.

@enyst enyst requested a review from rbren November 13, 2024 19:13
Copy link
Collaborator

@xingyaoww xingyaoww left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM! Thanks a bunch for this!

@enyst enyst enabled auto-merge (squash) November 14, 2024 19:13
@enyst enyst merged commit fac5237 into main Nov 14, 2024
12 checks passed
@enyst enyst deleted the enyst/user-commands branch November 14, 2024 19:14
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

Successfully merging this pull request may close these issues.

[Bug]: Tool call metadata should NOT be None when function calling is enabled
3 participants