cube-chat-tool 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ """cube-chat-tool: chat tool implementation for cube-standard benchmarks."""
2
+
3
+ from cube_chat_tool.chat_tool import ChatTool, ChatToolConfig
4
+
5
+ __all__ = ["ChatTool", "ChatToolConfig"]
@@ -0,0 +1,126 @@
1
+ """Chat tool for cube-standard benchmarks.
2
+
3
+ Provides ``ChatToolConfig`` and ``ChatTool``, a concrete implementation of the
4
+ ``Tool`` base class that wraps a ``ChatSession`` and exposes ``send_message``
5
+ as the single agent-facing action.
6
+ """
7
+
8
+ import datetime
9
+
10
+ from cube.resources.chat_session import ChatConfig, ChatRole, ChatSession
11
+ from cube.tool import Tool, ToolConfig, tool_action
12
+ from cube_chat import BasicChatConfig
13
+ from pydantic import Field
14
+
15
+
16
+ class ChatToolConfig(ToolConfig):
17
+ """Configuration for ``ChatTool``.
18
+
19
+ Parameters
20
+ ----------
21
+ chat : ChatConfig
22
+ Chat session configuration. Defaults to an in-memory BasicChatConfig.
23
+ """
24
+
25
+ chat: ChatConfig = Field(default_factory=BasicChatConfig)
26
+
27
+ def make(self, container=None) -> "ChatTool":
28
+ """Create a ChatTool from this configuration."""
29
+ session = self.chat.make()
30
+ return ChatTool(config=self, session=session)
31
+
32
+
33
+ class ChatTool(Tool):
34
+ """Chat tool that exposes a side-channel message interface to the agent.
35
+
36
+ The agent uses ``send_message`` to communicate with the task. The task uses
37
+ ``add_message`` and ``wait_for_user_message`` to drive the conversation.
38
+ After every agent action, ``chat_obs()`` is appended to the observation so
39
+ the agent always sees the up-to-date message history.
40
+
41
+ Call ``reset()`` between episodes to get a fresh session. Call ``close()``
42
+ to release session resources.
43
+ """
44
+
45
+ def __init__(self, config: ChatToolConfig, session: ChatSession) -> None:
46
+ self.config = config
47
+ self._session = session
48
+
49
+ @property
50
+ def session(self) -> ChatSession:
51
+ """Expose the raw ChatSession for advanced use (escape hatch, SR-003)."""
52
+ return self._session
53
+
54
+ @property
55
+ def messages(self) -> list[dict]:
56
+ """Delegate to session.messages."""
57
+ return self._session.messages
58
+
59
+ # ------------------------------------------------------------------
60
+ # Tool lifecycle
61
+ # ------------------------------------------------------------------
62
+
63
+ def reset(self) -> None:
64
+ """Stop the current session and create a fresh one."""
65
+ self._session.stop()
66
+ self._session = self.config.chat.make()
67
+
68
+ def close(self) -> None:
69
+ """Release session resources."""
70
+ self._session.stop()
71
+
72
+ # ------------------------------------------------------------------
73
+ # Task-internal methods (not agent-facing actions)
74
+ # ------------------------------------------------------------------
75
+
76
+ def add_message(self, role: ChatRole, msg: str) -> None:
77
+ """Post a message to the chat from the task side.
78
+
79
+ Parameters
80
+ ----------
81
+ role : ChatRole
82
+ Role of the message sender.
83
+ msg : str
84
+ Message content.
85
+ """
86
+ self._session.add_message(role, msg)
87
+
88
+ def wait_for_user_message(self) -> str:
89
+ """Block until the agent sends a message and return it.
90
+
91
+ Returns
92
+ -------
93
+ str
94
+ The agent's message text.
95
+ """
96
+ return self._session.wait_for_user_message()
97
+
98
+ def chat_obs(self) -> str:
99
+ """Format the full message history as a string.
100
+
101
+ Returns
102
+ -------
103
+ str
104
+ Formatted chat history with one line per message.
105
+ """
106
+ lines = []
107
+ for entry in self._session.messages:
108
+ ts = datetime.datetime.fromtimestamp(entry["timestamp"]).strftime("%H:%M:%S")
109
+ lines.append(f"[{ts}] {entry['role']}: {entry['message']}")
110
+ return "\n".join(lines)
111
+
112
+ # ------------------------------------------------------------------
113
+ # Agent-facing actions
114
+ # ------------------------------------------------------------------
115
+
116
+ @tool_action
117
+ def send_message(self, text: str) -> str:
118
+ """Send a message to the task.
119
+
120
+ Parameters
121
+ ----------
122
+ text : str
123
+ Message content to send.
124
+ """
125
+ self._session.send_message(text)
126
+ return self.chat_obs()
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.3
2
+ Name: cube-chat-tool
3
+ Version: 0.1.0
4
+ Summary: Chat tool implementation for cube-standard benchmarks
5
+ Requires-Dist: cube-standard
6
+ Requires-Dist: cube-chat
7
+ Requires-Dist: pytest>=8.0.0 ; extra == 'dev'
8
+ Requires-Python: >=3.12
9
+ Provides-Extra: dev
@@ -0,0 +1,5 @@
1
+ cube_chat_tool/__init__.py,sha256=7d5e69f3a42d0fae0922f1b94fcfbff365a620c2e5ecfc8577124510cbb44263,182
2
+ cube_chat_tool/chat_tool.py,sha256=187af1dc127306b42081e56c075816b4fde343e2a992e215b84dd80d67110f04,4025
3
+ cube_chat_tool-0.1.0.dist-info/WHEEL,sha256=2e78c4e84e52e71c127f39f0e9b8377baf8d97cfd8882e97be34163cff82eac7,79
4
+ cube_chat_tool-0.1.0.dist-info/METADATA,sha256=b60e7b2e045bc14930fd88e524a2d5a44dbc021602ae5d4fe29a84cadd138193,265
5
+ cube_chat_tool-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.6.17
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any