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

Move PromptManager to agent controller level #6526

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

xingyaoww
Copy link
Collaborator

@xingyaoww xingyaoww commented Jan 29, 2025

Description

This PR moves the PromptManager from CodeActAgent to the agent controller level and makes prompt extensions visible to users through the event stream.

Changes

  1. Added new action types:

    • SystemMessageAction - for system messages sent at initialization
    • PromptExtensionAction - for prompt extensions added after first user message
  2. Moved PromptManager initialization from CodeActAgent to AgentController:

    • Initialize PromptManager in AgentController
    • Send system message at initialization
    • Track first user message to trigger prompt extensions
  3. Updated CodeActAgent:

    • Removed PromptManager initialization
    • Added handling of new actions in get_action_message
    • Updated message conversion logic
  4. Fixed type issues:

    • Fixed prompt manager method calls to use Message objects
    • Fixed file path handling for dirname/join operations
    • Added proper imports for Message and TextContent

Benefits

  1. Better transparency: Users can now see when their prompts are being augmented through the event stream
  2. Better separation of concerns: PromptManager is now managed at the controller level
  3. Type safety: Fixed various type issues with prompt manager methods and file paths

Testing

All pre-commit checks pass, including:

  • Type checking with mypy
  • Code formatting with ruff
  • Other linting checks

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:7be2124-nikolaik   --name openhands-app-7be2124   docker.all-hands.dev/all-hands-ai/openhands:7be2124

1. Add new action types: SystemMessageAction and PromptExtensionAction
2. Move PromptManager initialization from CodeActAgent to AgentController
3. Send system message at initialization
4. Handle prompt extensions after first user message
5. Update CodeActAgent to handle new actions
6. Fix type issues with prompt manager methods and file paths
raise ValueError(f'Could not find file for module {agent_module.__name__}')
prompt_dir = os.path.join(os.path.dirname(agent_module_file), 'prompts')

self.prompt_manager = PromptManager(
Copy link
Contributor

Choose a reason for hiding this comment

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

we have specialized prompt manager for our sub agents, it subclass from PromptManager
for flexibility, it might be better to add a method to the agent class, for example:

self.prompt_manager = self.agent.get_prompt_manager(microagent_dir, prompt_dir, ...)

then specialized subagent implementations can override and return a different prompt manager

Otherwise, if every agent will now use the same PromptManager class, we wouldn't be able to subclass prompt manager anymore and have to push modifications into PromptManager directly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think one of the main motivations of bringing this to the controller level would be "we want to show these prompt extension actions as events to the user, so they need to be pushed to the eventstream".

But yeah, what you said definitely make sense! We could just have a .get_prompt_manager for the agent class :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants