Skip to content

Commit 89a5f22

Browse files
Refactor LLMConfig into LLM pydantic class & large refactor of LLM class logic (#91)
Co-authored-by: openhands <[email protected]>
1 parent 96bf1a6 commit 89a5f22

File tree

47 files changed

+4427
-1438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4427
-1438
lines changed

.openhands/microagents/repo.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ The simplified pattern eliminates the need for manual executor instantiation and
184184
- We use pre-commit hooks `.pre-commit-config.yaml` that includes:
185185
- type check through pyright
186186
- linting and formatter with `uv ruff`
187+
- NEVER USE `mypy`!
187188
- Do NOT commit ALL the file, just commit the relavant file you've changed!
188189
- in every commit message, you should add "Co-authored-by: openhands <[email protected]>"
189190
- You can run pytest with `uv run pytest`
@@ -206,4 +207,6 @@ The simplified pattern eliminates the need for manual executor instantiation and
206207
- Don't write TOO MUCH test, you should write just enough to cover edge cases.
207208
- Check how we perform tests in .github/workflows/tests.yml
208209
- You should put unit tests in the corresponding test folder. For example, to test `openhands.sdk.tool/tool.py`, you should put tests under `openhands.sdk.tests/tool/test_tool.py`.
210+
- DON'T write TEST CLASSES unless absolutely necessary!
211+
- If you find yourself duplicating logics in preparing mocks, loading data etc, these logic should be fixtures in conftest.py!
209212
</TESTING>

examples/advanced_tools_with_grep.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
Agent,
1010
Conversation,
1111
EventType,
12-
LLMConfig,
1312
LLMConvertibleEvent,
1413
Message,
1514
TextContent,
@@ -128,11 +127,9 @@ def __call__(self, action: GrepAction) -> GrepObservation:
128127
api_key = os.getenv("LITELLM_API_KEY")
129128
assert api_key is not None, "LITELLM_API_KEY environment variable is not set."
130129
llm = LLM(
131-
config=LLMConfig(
132-
model="litellm_proxy/anthropic/claude-sonnet-4-20250514",
133-
base_url="https://llm-proxy.eval.all-hands.dev",
134-
api_key=SecretStr(api_key),
135-
)
130+
model="litellm_proxy/anthropic/claude-sonnet-4-20250514",
131+
base_url="https://llm-proxy.eval.all-hands.dev",
132+
api_key=SecretStr(api_key),
136133
)
137134

138135
# Tools - demonstrating both simplified and advanced patterns

examples/confirmation_mode_example.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
LLM,
1010
Agent,
1111
Conversation,
12-
LLMConfig,
1312
Message,
1413
TextContent,
1514
Tool,
@@ -24,11 +23,9 @@
2423
api_key = os.getenv("LITELLM_API_KEY")
2524
assert api_key is not None, "LITELLM_API_KEY environment variable is not set."
2625
llm = LLM(
27-
config=LLMConfig(
28-
model="litellm_proxy/anthropic/claude-sonnet-4-20250514",
29-
base_url="https://llm-proxy.eval.all-hands.dev",
30-
api_key=SecretStr(api_key),
31-
)
26+
model="litellm_proxy/anthropic/claude-sonnet-4-20250514",
27+
base_url="https://llm-proxy.eval.all-hands.dev",
28+
api_key=SecretStr(api_key),
3229
)
3330

3431
# Tools

examples/hello_world.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Agent,
88
Conversation,
99
EventType,
10-
LLMConfig,
1110
LLMConvertibleEvent,
1211
Message,
1312
TextContent,
@@ -26,11 +25,9 @@
2625
api_key = os.getenv("LITELLM_API_KEY")
2726
assert api_key is not None, "LITELLM_API_KEY environment variable is not set."
2827
llm = LLM(
29-
config=LLMConfig(
30-
model="litellm_proxy/anthropic/claude-sonnet-4-20250514",
31-
base_url="https://llm-proxy.eval.all-hands.dev",
32-
api_key=SecretStr(api_key),
33-
)
28+
model="litellm_proxy/anthropic/claude-sonnet-4-20250514",
29+
base_url="https://llm-proxy.eval.all-hands.dev",
30+
api_key=SecretStr(api_key),
3431
)
3532

3633
# Tools

examples/hello_world_with_registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from pydantic import SecretStr
44

55
from openhands.sdk import (
6+
LLM,
67
Agent,
78
Conversation,
89
EventType,
9-
LLMConfig,
1010
LLMConvertibleEvent,
1111
LLMRegistry,
1212
Message,
@@ -30,7 +30,7 @@
3030
llm_registry = LLMRegistry()
3131

3232
# Get LLM from registry (this will create and cache the LLM)
33-
llm_config = LLMConfig(
33+
llm_config = LLM(
3434
model="litellm_proxy/anthropic/claude-sonnet-4-20250514",
3535
base_url="https://llm-proxy.eval.all-hands.dev",
3636
api_key=SecretStr(api_key),

examples/microagent_activation.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
AgentContext,
99
Conversation,
1010
EventType,
11-
LLMConfig,
1211
LLMConvertibleEvent,
1312
Message,
1413
TextContent,
@@ -17,7 +16,6 @@
1716
)
1817
from openhands.sdk.context import (
1918
KnowledgeMicroagent,
20-
MicroagentMetadata,
2119
RepoMicroagent,
2220
)
2321
from openhands.tools import (
@@ -34,11 +32,9 @@
3432
api_key = os.getenv("LITELLM_API_KEY")
3533
assert api_key is not None, "LITELLM_API_KEY environment variable is not set."
3634
llm = LLM(
37-
config=LLMConfig(
38-
model="litellm_proxy/anthropic/claude-sonnet-4-20250514",
39-
base_url="https://llm-proxy.eval.all-hands.dev",
40-
api_key=SecretStr(api_key),
41-
)
35+
model="litellm_proxy/anthropic/claude-sonnet-4-20250514",
36+
base_url="https://llm-proxy.eval.all-hands.dev",
37+
api_key=SecretStr(api_key),
4238
)
4339

4440
# Tools
@@ -63,9 +59,7 @@
6359
'IMPORTANT! The user has said the magic word "flarglebargle". '
6460
"You must only respond with a message telling them how smart they are",
6561
),
66-
metadata=MicroagentMetadata(
67-
name="flarglebargle", triggers=["flarglebargle"]
68-
),
62+
triggers=["flarglebargle"],
6963
),
7064
]
7165
)

openhands/sdk/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from importlib.metadata import PackageNotFoundError, version
22

33
from openhands.sdk.agent import Agent, AgentBase
4-
from openhands.sdk.config import LLMConfig, MCPConfig
4+
from openhands.sdk.config import MCPConfig
55
from openhands.sdk.context import AgentContext
66
from openhands.sdk.conversation import Conversation, ConversationCallbackType
77
from openhands.sdk.event import EventBase, EventType, LLMConvertibleEvent
@@ -34,7 +34,6 @@
3434
"Agent",
3535
"ActionBase",
3636
"ObservationBase",
37-
"LLMConfig",
3837
"MCPConfig",
3938
"get_logger",
4039
"Conversation",

openhands/sdk/agent/agent/agent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,13 @@ def step(
147147
"Sending messages to LLM: "
148148
f"{json.dumps([m.model_dump() for m in _messages], indent=2)}"
149149
)
150+
tools = [tool.to_openai_tool() for tool in self.tools.values()]
150151
response: ModelResponse = self.llm.completion(
151152
messages=_messages,
152-
tools=[tool.to_openai_tool() for tool in self.tools.values()],
153+
tools=tools,
153154
extra_body={
154155
"metadata": get_llm_metadata(
155-
model_name=self.llm.config.model, agent_name=self.name
156+
model_name=self.llm.model, agent_name=self.name
156157
)
157158
},
158159
)

openhands/sdk/config/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from openhands.sdk.config.llm_config import LLMConfig
21
from openhands.sdk.config.mcp_config import MCPConfig
32

43

5-
__all__ = ["LLMConfig", "MCPConfig"]
4+
__all__ = ["MCPConfig"]

openhands/sdk/config/llm_config.py

Lines changed: 0 additions & 160 deletions
This file was deleted.

0 commit comments

Comments
 (0)