Compare commits

...

2 Commits

Author SHA1 Message Date
rohitvinodmalhotra@gmail.com
b42c58f4f3 update default cli agent 2025-10-21 11:11:45 -04:00
rohitvinodmalhotra@gmail.com
59a45f0043 rename service_id 2025-10-21 11:05:53 -04:00
7 changed files with 29 additions and 19 deletions

View File

@@ -15,19 +15,17 @@ import sys
import time
from pathlib import Path
from openhands_cli.llm_utils import get_llm_metadata
from openhands_cli.utils import get_llm_metadata, get_default_cli_agent
from openhands_cli.locations import AGENT_SETTINGS_PATH, PERSISTENCE_DIR, WORK_DIR
from openhands.sdk import LLM
from openhands.tools.preset.default import get_default_agent
dummy_agent = get_default_agent(
dummy_agent = get_default_cli_agent(
llm=LLM(
model='dummy-model',
api_key='dummy-key',
metadata=get_llm_metadata(model_name='dummy-model', llm_type='openhands'),
),
cli_mode=True,
)
)
# =================================================

View File

@@ -1,13 +1,11 @@
import os
from openhands.sdk import LLM, BaseConversation, LocalFileStore
from openhands.sdk.security.confirmation_policy import NeverConfirm
from openhands.tools.preset.default import get_default_agent
from prompt_toolkit import HTML, print_formatted_text
from prompt_toolkit.shortcuts import print_container
from prompt_toolkit.widgets import Frame, TextArea
from openhands_cli.llm_utils import get_llm_metadata
from openhands_cli.utils import get_llm_metadata, get_default_cli_agent
from openhands_cli.locations import AGENT_SETTINGS_PATH, PERSISTENCE_DIR
from openhands_cli.pt_style import COLOR_GREY
from openhands_cli.tui.settings.store import AgentStore
@@ -176,13 +174,13 @@ class SettingsScreen:
model=model,
api_key=api_key,
base_url=base_url,
service_id='agent',
usage_id='agent',
metadata=get_llm_metadata(model_name=model, llm_type='agent'),
)
agent = self.agent_store.load()
if not agent:
agent = get_default_agent(llm=llm, cli_mode=True)
agent = get_default_cli_agent(llm=llm)
agent = agent.model_copy(update={'llm': llm})
self.agent_store.save(agent)

View File

@@ -2,6 +2,8 @@
import os
from typing import Any
from openhands.tools.preset.default import get_default_agent
from openhands.sdk import LLM
def get_llm_metadata(
@@ -55,3 +57,15 @@ def get_llm_metadata(
if user_id is not None:
metadata['trace_user_id'] = user_id
return metadata
def get_default_cli_agent(
llm: LLM
):
agent = get_default_agent(
llm=llm,
cli_mode = True,
add_security_analyzer = True
)
return agent

View File

@@ -9,7 +9,7 @@ from openhands_cli.user_actions.settings_action import SettingsType
from pydantic import SecretStr
from openhands.sdk import LLM, Conversation, LocalFileStore
from openhands.tools.preset.default import get_default_agent
from openhands_cli.utils import get_default_cli_agent
def read_json(path: Path) -> dict:
@@ -18,7 +18,7 @@ def read_json(path: Path) -> dict:
def make_screen_with_conversation(model='openai/gpt-4o-mini', api_key='sk-xyz'):
llm = LLM(model=model, api_key=SecretStr(api_key), service_id='test-service')
llm = LLM(model=model, api_key=SecretStr(api_key), usage_id='test-service')
# Conversation(agent) signature may vary across versions; adapt if needed:
from openhands.sdk.agent import Agent
@@ -30,8 +30,8 @@ def make_screen_with_conversation(model='openai/gpt-4o-mini', api_key='sk-xyz'):
def seed_file(path: Path, model: str = 'openai/gpt-4o-mini', api_key: str = 'sk-old'):
store = AgentStore()
store.file_store = LocalFileStore(root=str(path))
agent = get_default_agent(
llm=LLM(model=model, api_key=SecretStr(api_key), service_id='test-service')
agent = get_default_cli_agent(
llm=LLM(model=model, api_key=SecretStr(api_key), usage_id='test-service')
)
store.save(agent)

View File

@@ -50,7 +50,7 @@ class FakeAgent(AgentBase):
@pytest.fixture()
def agent() -> FakeAgent:
llm = LLM(**default_config(), service_id='test-service')
llm = LLM(**default_config(), usage_id='test-service')
return FakeAgent(llm=llm, tools=[])
@@ -102,11 +102,11 @@ class TestConversationRunner:
"""
if final_status == AgentExecutionStatus.FINISHED:
agent.finish_on_step = 1
# Add a mock security analyzer to enable confirmation mode
from unittest.mock import MagicMock
agent.security_analyzer = MagicMock()
convo = Conversation(agent)
convo.state.agent_status = AgentExecutionStatus.WAITING_FOR_CONFIRMATION
cr = ConversationRunner(convo)

View File

@@ -37,7 +37,7 @@ class TestToolFix:
"""Test that entire tools list is replaced with default tools when loading agent."""
# Create a mock agent with different tools and working directories
mock_agent = Agent(
llm=LLM(model='test/model', api_key='test-key', service_id='test-service'),
llm=LLM(model='test/model', api_key='test-key', usage_id='test-service'),
tools=[
Tool(name='BashTool'),
Tool(name='FileEditorTool'),

View File

@@ -26,7 +26,7 @@ def _create_agent(mcp_config=None) -> Agent:
if mcp_config is None:
mcp_config = {}
return Agent(
llm=LLM(model='test-model', api_key='test-key', service_id='test-service'),
llm=LLM(model='test-model', api_key='test-key', usage_id='test-service'),
tools=[],
mcp_config=mcp_config,
)