Skip to content

Commit 3d8af53

Browse files
authored
Agent Server UUIDs without hyphens (#960)
1 parent e1fc206 commit 3d8af53

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

openhands-agent-server/openhands/agent_server/conversation_service.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from openhands.agent_server.utils import utc_now
2323
from openhands.sdk import LLM, Event, Message
2424
from openhands.sdk.conversation.state import AgentExecutionStatus, ConversationState
25-
from openhands.sdk.utils.cipher import Cipher
2625

2726

2827
logger = logging.getLogger(__name__)
@@ -50,7 +49,6 @@ class ConversationService:
5049
conversations_dir: Path = field()
5150
webhook_specs: list[WebhookSpec] = field(default_factory=list)
5251
session_api_key: str | None = field(default=None)
53-
cipher: Cipher | None = field(default=None)
5452
_event_services: dict[UUID, EventService] | None = field(default=None, init=False)
5553
_conversation_webhook_subscribers: list["ConversationWebhookSubscriber"] = field(
5654
default_factory=list, init=False
@@ -300,12 +298,7 @@ async def __aenter__(self):
300298
if not meta_file.exists():
301299
continue
302300
json_str = meta_file.read_text()
303-
stored = StoredConversation.model_validate_json(
304-
json_str,
305-
context={
306-
"cipher": self.cipher,
307-
},
308-
)
301+
stored = StoredConversation.model_validate_json(json_str)
309302
await self._start_event_service(stored)
310303
except Exception:
311304
logger.exception(
@@ -344,7 +337,6 @@ def get_instance(cls, config: Config) -> "ConversationService":
344337
session_api_key=(
345338
config.session_api_keys[0] if config.session_api_keys else None
346339
),
347-
cipher=config.cipher,
348340
)
349341

350342
async def _start_event_service(self, stored: StoredConversation) -> EventService:
@@ -355,7 +347,6 @@ async def _start_event_service(self, stored: StoredConversation) -> EventService
355347
event_service = EventService(
356348
stored=stored,
357349
conversations_dir=self.conversations_dir,
358-
cipher=self.cipher,
359350
)
360351
# Create subscribers...
361352
await event_service.subscribe_to_events(_EventSubscriber(service=event_service))

openhands-agent-server/openhands/agent_server/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from datetime import datetime
33
from enum import Enum
44
from typing import Literal
5-
from uuid import UUID, uuid4
5+
from uuid import uuid4
66

77
from pydantic import BaseModel, Field
88

9-
from openhands.agent_server.utils import utc_now
9+
from openhands.agent_server.utils import OpenHandsUUID, utc_now
1010
from openhands.sdk import LLM, AgentBase, Event, ImageContent, Message, TextContent
1111
from openhands.sdk.conversation.secret_source import SecretSource
1212
from openhands.sdk.conversation.state import AgentExecutionStatus, ConversationState
@@ -64,7 +64,7 @@ class StartConversationRequest(BaseModel):
6464
...,
6565
description="Working directory for agent operations and tool execution",
6666
)
67-
conversation_id: UUID | None = Field(
67+
conversation_id: OpenHandsUUID | None = Field(
6868
default=None,
6969
description=(
7070
"Optional conversation ID. If not provided, a random UUID will be "
@@ -99,7 +99,7 @@ class StartConversationRequest(BaseModel):
9999
class StoredConversation(StartConversationRequest):
100100
"""Stored details about a conversation"""
101101

102-
id: UUID
102+
id: OpenHandsUUID
103103
title: str | None = Field(
104104
default=None, description="User-defined title for the conversation"
105105
)
@@ -190,7 +190,7 @@ class GenerateTitleResponse(BaseModel):
190190
class BashEventBase(DiscriminatedUnionMixin, ABC):
191191
"""Base class for all bash event types"""
192192

193-
id: UUID = Field(default_factory=uuid4)
193+
id: OpenHandsUUID = Field(default_factory=uuid4)
194194
timestamp: datetime = Field(default_factory=utc_now)
195195

196196

@@ -213,7 +213,7 @@ class BashOutput(BashEventBase):
213213
depending on how large the output is.
214214
"""
215215

216-
command_id: UUID
216+
command_id: OpenHandsUUID
217217
order: int = Field(
218218
default=0, description="The order for this output, sequentially starting with 0"
219219
)

openhands-agent-server/openhands/agent_server/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
from datetime import UTC, datetime
2+
from typing import Annotated
3+
from uuid import UUID
4+
5+
from pydantic import PlainSerializer
26

37

48
def utc_now():
@@ -177,3 +181,11 @@ def _patched_openapi(self):
177181
except (ImportError, AttributeError):
178182
# FastAPI not available or internal API changed
179183
pass
184+
185+
186+
def _uuid_to_hex(uuid_obj: UUID) -> str:
187+
"""Converts a UUID object to a hex string without hyphens."""
188+
return uuid_obj.hex
189+
190+
191+
OpenHandsUUID = Annotated[UUID, PlainSerializer(_uuid_to_hex, when_used="json")]

0 commit comments

Comments
 (0)