Hi! Is there a guide on running custom agents buil...
# questions
e
Hi! Is there a guide on running custom agents built with openhands sdk from Openhands server web UI? My case is I want to select and use specific agent for specific conversation.
m
Hey Alexander, Thanks for your question. Just a quick clarification: when you say you want to select a specific agent for a specific conversation, do you mean starting a new chat with an agent that has a custom system prompt and specific tools for that use case?
e
I mean starting a new chat with an agent defined as a custom class, like this - https://github.com/OpenHands/software-agent-sdk/blob/main/examples/01_standalone_sdk/35_subscription_login.py
m
I'm sorry, but I don't understand the question 100%. --- User case A An Agent is composed of different parts: LLM, tools, MCPs, etc. In the example you are pointing to, you are changing the LLM component inside the Agent class. So I suppose you want to be able to start a new conversation with your chosen/specific LLM. For example: • conversation about coding → use Sonnet as LLM • conversation about poetry → use Gemini as LLM If the above describes your use case, the SDK has a new method in
LocalConversation
that allows you to switch LLMs inside a conversation. (link). However, this change is only in the SDK and there is no user-facing implementation yet. -- User case B If you want to start a conversation and select an agent based on the theme of the conversation, for example: • conversation about coding → use Sonnet as LLM with specific coding tools • conversation about poetry → use Gemini as LLM and an MCP connected to a poetry library There is no default way to do this. You can create specific sub-agents (using file-based agents) for your tasks, and when you start a new conversation you can prompt the main agent to use a specific sub-agent. (Or the main agent will probably figure it out on its own.) Let me know if this answer your question
e
Thank you for your answer, @modern-fireman-99755! But can you point me to a simple step-by-step guide on how to integrate it with openhands server? I am totally lost here
m
No problem. For which user case? A or/and B?
e
Case A
m
@nutritious-balloon-65098 Could you create a step-by-step guide for Use Case A? You can find all the relevant information in the messages above. If it is not possible to implement a solution, please explain clearly why. In any case, please stay concise in your response.
n
I'm on it! Vasco can track my progress here.
## Summary Question Asked: Is there a step-by-step guide for Use Case A (selecting a specific LLM for a specific conversation via OpenHands server web UI)? Answer: No, this is not currently possible via the web UI for mid-conversation LLM switching. ### Key Findings: 1. SDK Support Exists: The SDK has
LocalConversation.switch_profile()
method (added in PR #2192) that allows switching LLMs mid-conversation programmatically. 2. Agent-Server Gap: The agent-server does not expose a REST API endpoint for
switch_profile
, so the web UI cannot trigger this functionality. 3. What Works Today: - ✅ You can start different conversations with different LLMs by specifying the LLM in the
Agent
config when calling
POST /conversations
- ❌ You cannot switch LLMs within an active conversation via the web UI ### Workarounds: - Programmatic approach: Use the SDK directly with
LocalConversation.switch_profile("profile_name")
- Per-conversation approach: Start each new conversation with the desired LLM configuration via the API ### Bottom Line: The feature exists in the SDK but hasn't been propagated to the agent-server API or web UI yet. Users who need mid-conversation LLM switching must use the SDK directly for now.
e
@nutritious-balloon-65098 how do I initiate a conversation with custom agent so that it is visible in openhands server web ui? Give me an example API request and, if needed, additional configuration steps
m
@nutritious-balloon-65098 how do I initiate a conversation with custom agent so that it is visible in openhands server web ui? Give me an example API request and, if needed, additional configuration steps
n
I'm on it! Vasco can track my progress here.
## Summary I answered the user's question about how to initiate a conversation with a custom agent via the OpenHands server API so it appears in the web UI. No code changes were made - this was a documentation/guidance task only. --- ### Answer Summary To create a conversation with a custom agent visible in the OpenHands web UI, use the
POST /conversations
API endpoint: 1. Setup:
Copy code
bash
export OH_SECRET_KEY=$(openssl rand -hex 32)  # Required for persisting API keys
2. API Request Example:
Copy code
bash
curl -X POST "<http://localhost:8000/conversations>" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": {
      "kind": "Agent",
      "llm": {
        "model": "anthropic/claude-sonnet-4-20250514",
        "api_key": "your-llm-api-key"
      },
      "tools": [
        {"name": "TerminalTool"},
        {"name": "FileEditorTool"}
      ]
    },
    "workspace": {
      "kind": "LocalWorkspace",
      "working_dir": "workspace/project"
    },
    "initial_message": {
      "role": "user",
      "content": [{"kind": "TextContent", "text": "Hello!"}],
      "run": true
    }
  }'
3. Key Points: - Each conversation is created with its own agent configuration (LLM, tools, workspace) - Different conversations can use different LLMs - The conversation will appear in the web UI after creation - Full API documentation is available at
<http://localhost:8000/docs>
l
@modern-fireman-99755 if this is helpful you can send a PR to OpenHands/docs
👍 1