Skip to content

Commit ee5a976

Browse files
authored
Updates doc assistant (#615)
To use new APIs
1 parent 6c453d7 commit ee5a976

9 files changed

Lines changed: 63 additions & 38 deletions

File tree

.github/workflows/libraries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
run: uv python install ${{ matrix.python-version }}
3737

3838
- name: Install and run tests
39-
run: make test
39+
run: make -j $(nproc) test

assistants/document-assistant/assistant/chat.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
import deepmerge
1313
from assistant_extensions import dashboard_card, navigator
14-
from assistant_extensions.chat_context_toolkit.archive import ArchiveTaskQueues
14+
from assistant_extensions.attachments import get_attachments
15+
from assistant_extensions.chat_context_toolkit.archive import ArchiveTaskQueues, construct_archive_summarizer
16+
from assistant_extensions.chat_context_toolkit.message_history import construct_attachment_summarizer
1517
from assistant_extensions.mcp import MCPServerConfig
1618
from chat_context_toolkit.archive import ArchiveTaskConfig
1719
from content_safety.evaluators import CombinedContentSafetyEvaluator
@@ -209,11 +211,21 @@ async def on_message_created(
209211
)
210212
)
211213

214+
attachments = await get_attachments(
215+
context=context,
216+
summarizer=construct_attachment_summarizer(
217+
service_config=config.generative_ai_fast_client_config.service_config,
218+
request_config=config.generative_ai_fast_client_config.request_config,
219+
),
220+
)
212221
await archive_task_queues.enqueue_run(
213222
context=context,
214-
service_config=config.generative_ai_client_config.service_config,
215-
request_config=config.generative_ai_client_config.request_config,
223+
attachments=attachments,
216224
archive_task_config=ArchiveTaskConfig(chunk_token_count_threshold=30_000),
225+
archive_summarizer=construct_archive_summarizer(
226+
service_config=config.generative_ai_fast_client_config.service_config,
227+
request_config=config.generative_ai_fast_client_config.request_config,
228+
),
217229
)
218230

219231

assistants/document-assistant/assistant/filesystem/_file_sources.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Callable, Iterable
33

44
from assistant_drive import Drive
5-
from chat_context_toolkit.virtual_filesystem import DirectoryEntry, FileEntry, MountPoint, WriteToolDefinition
5+
from chat_context_toolkit.virtual_filesystem import DirectoryEntry, FileEntry, MountPoint
66
from semantic_workbench_assistant.assistant_app import ConversationContext
77

88
from assistant.filesystem._filesystem import AttachmentsExtension, _get_attachments, log_and_send_message_on_error
@@ -17,11 +17,6 @@ def __init__(self, context: ConversationContext, attachments_extension: Attachme
1717
self.context = context
1818
self.attachments_extension = attachments_extension
1919

20-
@property
21-
def write_tools(self) -> Iterable[WriteToolDefinition]:
22-
"""Get the list of write tools provided by this file system provider."""
23-
return []
24-
2520
async def list_directory(self, path: str) -> Iterable[DirectoryEntry | FileEntry]:
2621
"""
2722
List files and directories at the specified path.
@@ -86,11 +81,6 @@ def __init__(self, context: ConversationContext, drive_provider: Callable[[Conve
8681
self.context = context
8782
self.drive_provider = drive_provider
8883

89-
@property
90-
def write_tools(self) -> Iterable[WriteToolDefinition]:
91-
"""Get the list of write tools provided by this file system provider."""
92-
return []
93-
9484
async def list_directory(self, path: str) -> Iterable[DirectoryEntry | FileEntry]:
9585
"""
9686
List files and directories at the specified path.

assistants/document-assistant/assistant/response/completion_handler.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,13 @@
4444

4545

4646
async def handle_completion(
47-
sampling_handler: OpenAISamplingHandler,
4847
step_result: StepResult,
4948
completion: ParsedChatCompletion | ChatCompletion,
5049
mcp_sessions: List[MCPSession],
5150
context: ConversationContext,
5251
request_config: OpenAIRequestConfig,
53-
silence_token: str,
5452
metadata_key: str,
5553
response_start_time: float,
56-
attachments_extension: AttachmentsExtension,
5754
guidance_enabled: bool,
5855
virtual_filesystem: VirtualFileSystem,
5956
) -> StepResult:

assistants/document-assistant/assistant/response/responder.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,13 @@ async def _step(self, step_count) -> StepResult:
324324
await update_dynamic_ui_state(self.context, tool_call.arguments)
325325

326326
step_result = await handle_completion(
327-
self.sampling_handler,
328327
step_result,
329328
completion,
330329
self.mcp_sessions,
331330
self.context,
332331
self.config.generative_ai_client_config.request_config,
333-
"SILENCE", # TODO: This is not being used correctly.
334332
f"respond_to_conversation:step_{step_count}",
335333
response_start_time,
336-
self.attachments_extension,
337334
self.config.orchestration.guidance.enabled,
338335
self.virtual_filesystem,
339336
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from ._ls_tool import LsTool
1+
from ._ls_tool import LsTool, LsToolOptions
22
from ._tools import ToolCollection, tool_result_to_string
33
from ._view_tool import ViewTool
44

5-
__all__ = ["LsTool", "ToolCollection", "ViewTool", "tool_result_to_string"]
5+
__all__ = ["LsTool", "ToolCollection", "ViewTool", "tool_result_to_string", "LsToolOptions"]

libraries/python/chat-context-toolkit/chat_context_toolkit/virtual_filesystem/tools/_ls_tool.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
from dataclasses import dataclass
12
from typing import Iterable
3+
24
from openai.types.chat import ChatCompletionContentPartTextParam, ChatCompletionToolParam
35

46
from chat_context_toolkit.virtual_filesystem._types import DirectoryEntry, FileEntry, ToolDefinition
57
from chat_context_toolkit.virtual_filesystem._virtual_filesystem import VirtualFileSystem
68

79

10+
@dataclass
11+
class LsToolOptions:
12+
tool_name: str = "ls"
13+
"""Name of the tool provided to the LLM."""
14+
tool_description: str = "List files and directories at the specified path. Root directories: {root_path_list}"
15+
"""Description of the tool provided to the LLM."""
16+
path_argument_description: str = "The path to list (e.g., '/', '/docs', '/docs/subdir)"
17+
"""Description of the 'path' argument."""
18+
19+
820
class LsTool(ToolDefinition):
921
"""Tool for listing files and directories in the virtual file system."""
1022

11-
def __init__(self, virtual_filesystem: VirtualFileSystem):
23+
def __init__(self, virtual_filesystem: VirtualFileSystem, options: LsToolOptions = LsToolOptions()) -> None:
1224
self.virtual_filesystem = virtual_filesystem
25+
self.options = options
1326

1427
@property
1528
def tool_param(self) -> ChatCompletionToolParam:
@@ -20,14 +33,14 @@ def tool_param(self) -> ChatCompletionToolParam:
2033
return ChatCompletionToolParam(
2134
type="function",
2235
function={
23-
"name": "ls",
24-
"description": "List files and directories at the specified path. Root directories: " + mount_list,
36+
"name": self.options.tool_name,
37+
"description": self.options.tool_description.format(root_path_list=mount_list),
2538
"parameters": {
2639
"type": "object",
2740
"properties": {
2841
"path": {
2942
"type": "string",
30-
"description": "The path to list (e.g., '/', '/docs', '/docs/subdir')",
43+
"description": self.options.path_argument_description.format(root_path_list=mount_list),
3144
}
3245
},
3346
"required": ["path"],
@@ -39,7 +52,7 @@ async def execute(self, args: dict) -> str | Iterable[ChatCompletionContentPartT
3952
"""Execute the built-in ls tool to list directory contents."""
4053
path = args.get("path")
4154
if not path:
42-
return "Error: 'path' argument is required for the ls tool"
55+
return f"Error: 'path' argument is required for the {self.options.tool_name} tool"
4356

4457
try:
4558
entries = await self.virtual_filesystem.list_directory(path)
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
1+
from dataclasses import dataclass
12
from typing import Iterable
3+
4+
from openai.types.chat import ChatCompletionContentPartTextParam, ChatCompletionToolParam
5+
26
from chat_context_toolkit.virtual_filesystem._types import ToolDefinition
37
from chat_context_toolkit.virtual_filesystem._virtual_filesystem import VirtualFileSystem
4-
from openai.types.chat import ChatCompletionContentPartTextParam, ChatCompletionToolParam
8+
9+
10+
@dataclass
11+
class ViewToolOptions:
12+
tool_name: str = "view"
13+
"""Name of the tool provided to the LLM."""
14+
tool_description: str = "Read the contents of a file at the specified path"
15+
"""Description of the tool provided to the LLM."""
16+
path_argument_description: str = "The path to the file to read (e.g., '/docs/file.txt')"
17+
"""Description of the 'path' argument."""
518

619

720
class ViewTool(ToolDefinition):
821
"""Tool for viewing the contents of a file in the virtual file system."""
922

10-
def __init__(self, virtual_filesystem: VirtualFileSystem, tool_name: str = "view"):
23+
def __init__(self, virtual_filesystem: VirtualFileSystem, options: ViewToolOptions = ViewToolOptions()) -> None:
1124
self.virtual_filesystem = virtual_filesystem
12-
self.tool_name = tool_name
25+
self.options = options
1326

1427
@property
1528
def tool_param(self) -> ChatCompletionToolParam:
1629
return ChatCompletionToolParam(
1730
type="function",
1831
function={
19-
"name": self.tool_name,
20-
"description": "Read the contents of a file at the specified path",
32+
"name": self.options.tool_name,
33+
"description": self.options.tool_description,
2134
"parameters": {
2235
"type": "object",
2336
"properties": {
2437
"path": {
2538
"type": "string",
26-
"description": "The path to the file to read (e.g., '/docs/file.txt')",
39+
"description": self.options.path_argument_description,
2740
}
2841
},
2942
"required": ["path"],
@@ -35,12 +48,12 @@ async def execute(self, args: dict) -> str | Iterable[ChatCompletionContentPartT
3548
"""Execute the built-in view tool to read file contents."""
3649
path = args.get("path")
3750
if not path:
38-
return "Error: 'path' argument is required for the view tool"
51+
return f"Error: 'path' argument is required for the {self.options.tool_name} tool"
3952

4053
try:
4154
file_content = await self.virtual_filesystem.read_file(path)
4255
except FileNotFoundError:
4356
return f"Error: File at path {path} not found. Please pay attention to the available files and try again."
4457

45-
result = f"<file path={path}>\n{file_content}\n</file>"
58+
result = f'<file path="{path}">\n{file_content}\n</file>'
4659
return result

libraries/python/chat-context-toolkit/test/virtual_filesystem/tools/test_view_tool.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async def test_builtin_view_tool_reads_file():
1414
result = await view_tool.execute({"path": "/docs/file1.txt"})
1515

1616
mock_vfs.read_file.assert_called_once_with("/docs/file1.txt")
17-
assert result == "<file path=/docs/file1.txt>\nHello World\n</file>"
17+
assert result == '<file path="/docs/file1.txt">\nHello World\n</file>'
1818

1919

2020
async def test_view_tool_error_handling():
@@ -25,4 +25,7 @@ async def test_view_tool_error_handling():
2525
# view on non-existent file should raise error
2626
view_tool = ViewTool(mock_vfs)
2727
result = await view_tool.execute({"path": "/nonexistent.txt"})
28-
assert result == "Error: File at path /nonexistent.txt not found. Please pay attention to the available files and try again."
28+
assert (
29+
result
30+
== "Error: File at path /nonexistent.txt not found. Please pay attention to the available files and try again."
31+
)

0 commit comments

Comments
 (0)