Skip to content

Commit 786a089

Browse files
Upgrade models and update prompts (#534)
1 parent 35b86ff commit 786a089

16 files changed

Lines changed: 180 additions & 80 deletions

File tree

assistants/document-assistant/assistant/config.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ class PromptsConfigModel(BaseModel):
194194
- 🧪 Ask me to conduct research for example, *Find me the latest competitors in the wearables market*
195195
""").strip()
196196

197+
knowledge_cutoff: Annotated[
198+
str,
199+
Field(
200+
title="Knowledge Cutoff",
201+
description="Knowledge cutoff date for the models being used.",
202+
),
203+
] = "2024-05"
204+
197205

198206
class OrchestrationConfigModel(BaseModel):
199207
hosted_mcp_servers: Annotated[
@@ -278,7 +286,7 @@ class AssistantConfigModel(BaseModel):
278286
] = AzureOpenAIClientConfigModel(
279287
service_config=azure_openai_service_config_construct(default_deployment="gpt-4.1"),
280288
request_config=OpenAIRequestConfig(
281-
max_tokens=128_000,
289+
max_tokens=180000,
282290
response_tokens=16_384,
283291
model="gpt-4.1",
284292
is_reasoning_model=False,
@@ -294,11 +302,11 @@ class AssistantConfigModel(BaseModel):
294302
),
295303
UISchema(widget="radio", hide_title=True),
296304
] = AzureOpenAIClientConfigModel(
297-
service_config=azure_openai_service_config_reasoning_construct(default_deployment="o3-mini"),
305+
service_config=azure_openai_service_config_reasoning_construct(default_deployment="o4-mini"),
298306
request_config=OpenAIRequestConfig(
299307
max_tokens=200_000,
300308
response_tokens=65_536,
301-
model="o3-mini",
309+
model="o4-mini",
302310
is_reasoning_model=True,
303311
reasoning_effort="high",
304312
),

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from ._filesystem import AttachmentProcessingErrorHandler, AttachmentsExtension
22
from ._model import Attachment, AttachmentsConfigModel, DocumentEditorConfigModel
3-
from ._prompts import FILES_PROMPT, VIEW_TOOL, VIEW_TOOL_OBJ
3+
from ._prompts import EDIT_TOOL_DESCRIPTION_HOSTED, EDIT_TOOL_DESCRIPTION_LOCAL, FILES_PROMPT, VIEW_TOOL, VIEW_TOOL_OBJ
44

55
__all__ = [
66
"AttachmentsExtension",
@@ -11,4 +11,6 @@
1111
"FILES_PROMPT",
1212
"VIEW_TOOL",
1313
"VIEW_TOOL_OBJ",
14+
"EDIT_TOOL_DESCRIPTION_HOSTED",
15+
"EDIT_TOOL_DESCRIPTION_LOCAL",
1416
]

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,28 @@
4242
),
4343
type="function",
4444
)
45+
46+
EDIT_TOOL_DESCRIPTION_HOSTED = """Edits the Markdown file at the provided path, focused on the given task.
47+
The user has Markdown editor available that is side by side with this chat.
48+
Remember that the editable files are the ones that have the `-rw-` permission bits. \
49+
If you provide a new file path, it will be created for you and then the editor will start to edit it (from scratch). \
50+
Name the file with capital letters and spacing like "Weekly AI Report.md" or "Email to Boss.md" since it will be directly shown to the user in that way.
51+
Provide a task that you want it to do in the document. For example, if you want to have it expand on one section, \
52+
you can say "expand on the section about <topic x>". The task should be at most a few sentences. \
53+
Do not provide it any additional context outside of the task parameter. It will automatically be fetched as needed by this tool.
54+
55+
Args:
56+
path: The relative path to the file.
57+
task: The specific task that you want the document editor to do."""
58+
59+
EDIT_TOOL_DESCRIPTION_LOCAL = """The user has a file editor corresponding to the file type, open like VSCode, Word, PowerPoint, TeXworks (+ MiKTeX), open side by side with this chat.
60+
Use this tool to create new files or edit existing ones.
61+
If you provide a new file path, it will be created for you and then the editor will start to edit it (from scratch).
62+
Name the file with capital letters and spacing like "Weekly AI Report.md" or "Email to Boss.md" since it will be directly shown to the user in that way.
63+
Provide a task that you want it to do in the document. For example, if you want to have it expand on one section,
64+
you can say "expand on the section about <topic x>". The task should be at most a few sentences.
65+
Do not provide it any additional context outside of the task parameter. It will automatically be fetched as needed by this tool.
66+
67+
Args:
68+
path: The relative path to the file.
69+
task: The specific task that you want the document editor to do."""

assistants/document-assistant/assistant/guidance/guidance_prompts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
since there might be a lot of UI elements generated over time and we want to make sure the user can understand what it is referring to.
3535
3636
### Current Dynamic UI State
37+
3738
- The current UI schema is after the "ui_elements" key in the JSON object.
3839
- The current selections (if any) are in the "form_data" key in the JSON object. \
3940
Note that textboxes are indexed by their order in the list of UI elements, so the first textbox if it has data will be "textbox_0", the second "textbox_1", etc.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
freeing them up to be more focused on higher level objectives once you understand their needs and goals. \
66
One of the core features is a Markdown document editor that will be open side by side whenever a document is opened or edited. \
77
They are counting on you, so be creative, guiding, work hard, and find ways to be successful.
8+
Knowledge cutoff: {{knowledge_cutoff}}
9+
Current date: {{current_date}}
810
911
# On Responding in Chat (Formatting)
1012
- **Text & Markdown:**

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

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Any, Callable
77

88
import deepmerge
9+
import pendulum
910
from assistant_extensions.mcp import (
1011
ExtendedCallToolRequestParams,
1112
MCPClientSettings,
@@ -18,6 +19,7 @@
1819
refresh_mcp_sessions,
1920
sampling_message_to_chat_completion_message,
2021
)
22+
from liquid import render
2123
from mcp import SamplingMessage, ServerNotification
2224
from mcp.types import (
2325
TextContent,
@@ -47,12 +49,17 @@
4749
)
4850

4951
from assistant.config import AssistantConfigModel
50-
from assistant.filesystem import VIEW_TOOL_OBJ, AttachmentsExtension
52+
from assistant.filesystem import (
53+
EDIT_TOOL_DESCRIPTION_HOSTED,
54+
EDIT_TOOL_DESCRIPTION_LOCAL,
55+
VIEW_TOOL_OBJ,
56+
AttachmentsExtension,
57+
)
58+
from assistant.filesystem._prompts import FILES_PROMPT
5159
from assistant.guidance.dynamic_ui_inspector import get_dynamic_ui_state, update_dynamic_ui_state
5260
from assistant.guidance.guidance_prompts import DYNAMIC_UI_TOOL_NAME, DYNAMIC_UI_TOOL_OBJ
5361
from assistant.response.completion_handler import handle_completion
5462
from assistant.response.models import StepResult
55-
from assistant.response.prompts import GUARDRAILS_POSTFIX, ORCHESTRATION_SYSTEM_PROMPT
5663
from assistant.response.utils import get_ai_client_configs, get_completion, get_openai_tools_from_mcp_sessions
5764
from assistant.response.utils.formatting_utils import format_message
5865
from assistant.response.utils.message_utils import (
@@ -299,9 +306,19 @@ async def _construct_prompt(self) -> tuple[list, list[ChatCompletionMessageParam
299306
# Remove any view tool that was added by an MCP server and replace it with ours
300307
tools = [tool for tool in tools if tool["function"]["name"] != "view"]
301308
tools.append(VIEW_TOOL_OBJ)
309+
# Override the description of the edit_file depending on the environment
310+
tools = self._override_edit_file_description(tools)
302311

303312
# Start constructing main system prompt
304-
main_system_prompt = ORCHESTRATION_SYSTEM_PROMPT
313+
main_system_prompt = self.config.orchestration.prompts.orchestration_prompt
314+
# Inject the {{knowledge_cutoff}} and {{current_date}} placeholders
315+
main_system_prompt = render(
316+
main_system_prompt,
317+
**{
318+
"knowledge_cutoff": self.config.orchestration.prompts.knowledge_cutoff,
319+
"current_date": pendulum.now(tz="America/Los_Angeles").format("YYYY-MM-DD"),
320+
},
321+
)
305322

306323
# Construct key parts of the system messages which are core capabilities.
307324
# Best practice is to have these start with a ## <heading content>
@@ -310,23 +327,23 @@ async def _construct_prompt(self) -> tuple[list, list[ChatCompletionMessageParam
310327
dynamic_ui_system_prompt = self.tokenizer.truncate_str(
311328
await self._construct_dynamic_ui_system_prompt(), self.max_system_prompt_component_tokens
312329
)
313-
main_system_prompt += "\n\n" + dynamic_ui_system_prompt
330+
main_system_prompt += "\n\n" + dynamic_ui_system_prompt.strip()
314331

315332
# Filesystem System Prompt
316333
filesystem_system_prompt = self.tokenizer.truncate_str(
317334
await self._construct_filesystem_system_prompt(), self.max_system_prompt_component_tokens
318335
)
319-
main_system_prompt += "\n\n" + filesystem_system_prompt
336+
main_system_prompt += "\n\n" + filesystem_system_prompt.strip()
320337

321338
# Add specific guidance from MCP servers
322339
mcp_prompts = await get_mcp_server_prompts(self.mcp_sessions)
323340
mcp_prompt_string = self.tokenizer.truncate_str(
324341
"## MCP Servers" + "\n\n" + "\n\n".join(mcp_prompts), self.max_system_prompt_component_tokens
325342
)
326-
main_system_prompt += "\n\n" + mcp_prompt_string
343+
main_system_prompt += "\n\n" + mcp_prompt_string.strip()
327344

328345
# Always append the guardrails postfix at the end.
329-
main_system_prompt += "\n\n" + GUARDRAILS_POSTFIX
346+
main_system_prompt += "\n\n" + self.config.orchestration.prompts.guardrails_prompt.strip()
330347

331348
logging.info("The system prompt has been constructed.")
332349

@@ -435,7 +452,7 @@ async def _construct_dynamic_ui_system_prompt(self) -> str:
435452
if not current_dynamic_ui_elements:
436453
current_dynamic_ui_elements = "No dynamic UI elements have been generated yet. Consider generating some."
437454

438-
system_prompt = "## On Dynamic UI Elements"
455+
system_prompt = "## On Dynamic UI Elements\n"
439456
system_prompt += "\n" + self.config.orchestration.guidance.prompt
440457
system_prompt += "\n" + str(current_dynamic_ui_elements)
441458
return system_prompt
@@ -454,7 +471,7 @@ async def _construct_filesystem_system_prompt(self) -> str:
454471
all_files.extend([(filename, "-rw-") for filename in doc_editor_filenames])
455472
all_files.sort(key=lambda x: x[0])
456473

457-
system_prompt = "## Files\n"
474+
system_prompt = f"{FILES_PROMPT}" + "\n\n### Files\n"
458475
if not all_files:
459476
system_prompt += "\nNo files have been added or created yet."
460477
else:
@@ -537,6 +554,39 @@ async def _context_management(
537554
preserved_messages = initial_messages + recent_messages
538555
return preserved_messages
539556

557+
def _override_edit_file_description(self, tools: list[ChatCompletionToolParam]) -> list[ChatCompletionToolParam]:
558+
"""
559+
Override the edit_file description based on the root (the one that indicates the hosted env, otherwise assume the local env).
560+
"""
561+
try:
562+
# Get the root of the filesystem-edit tool
563+
# Find the filesystem MCP by name
564+
filesystem_mcp = next(
565+
(mcp for mcp in self.mcp_sessions if mcp.config.server_config.key == "filesystem-edit"),
566+
None,
567+
)
568+
filesystem_root = None
569+
if filesystem_mcp:
570+
# Get the root of the filesystem-edit tool
571+
filesystem_root = next(
572+
(root for root in filesystem_mcp.config.server_config.roots if root.name == "root"),
573+
None,
574+
)
575+
576+
edit_tool = next(
577+
(tool for tool in tools if tool["function"]["name"] == "edit_file"),
578+
None,
579+
)
580+
if filesystem_root and filesystem_root.uri == "file://workspace" and edit_tool:
581+
edit_tool["function"]["description"] = EDIT_TOOL_DESCRIPTION_HOSTED
582+
elif filesystem_root and edit_tool:
583+
edit_tool["function"]["description"] = EDIT_TOOL_DESCRIPTION_LOCAL
584+
except Exception as e:
585+
logger.error(f"Failed to override edit_file description: {e}")
586+
return tools
587+
588+
return tools
589+
540590
# endregion
541591

542592
# region MCP Sessions

assistants/document-assistant/assistant/response/utils/formatting_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from textwrap import dedent
33

4+
import pendulum
45
from semantic_workbench_api_model.workbench_model import (
56
ConversationMessage,
67
ConversationParticipant,
@@ -18,7 +19,8 @@ def format_message(message: ConversationMessage, participants: list[Conversation
1819
None,
1920
)
2021
participant_name = conversation_participant.name if conversation_participant else "unknown"
21-
message_datetime = message.timestamp.strftime("%Y-%m-%d %H:%M:%S")
22+
message_datetime = pendulum.instance(message.timestamp, tz="America/Los_Angeles")
23+
message_datetime = message_datetime.format("Y-MM-DD HH:mm:ss")
2224
return f"[{participant_name} - {message_datetime}]: {message.content}"
2325

2426

assistants/document-assistant/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies = [
1616
"openai-client>=0.1.0",
1717
"pdfplumber>=0.11.2",
1818
"pendulum>=3.1,<4.0",
19+
"python-liquid>=2.0,<3.0",
1920
"tiktoken>=0.9.0",
2021
]
2122

assistants/document-assistant/uv.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libraries/python/mcp-extensions/mcp_extensions/llm/mcp_chat_completion.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,30 @@ async def mcp_chat_completion(request: ChatCompletionRequest, client: Context) -
7373
extra_args["response_format"] = response_format
7474

7575
model = request.model
76-
# Default to gpt-4o
77-
model_preferences = ModelPreferences(intelligencePriority=0, speedPriority=1)
78-
if model.startswith("o3"):
76+
if model in [
77+
"gpt-4o",
78+
"gpt-4o-2024-11-20",
79+
"gpt-4o-2024-08-06",
80+
"gpt-4o-2024-05-13",
81+
"gpt-4.1",
82+
"gpt-4.1-2025-04-14",
83+
]:
84+
model_preferences = ModelPreferences(intelligencePriority=0, speedPriority=1)
85+
elif model in [
86+
"o3",
87+
"o3-2025-04-16",
88+
"o3-mini",
89+
"o3-mini-2025-01-31",
90+
"o4-mini",
91+
"o4-mini-2025-04-16",
92+
"o1-mini",
93+
"o1-mini-2024-09-12",
94+
]:
7995
model_preferences = ModelPreferences(intelligencePriority=1)
96+
else:
97+
model_preferences = ModelPreferences(intelligencePriority=0, speedPriority=1)
8098

99+
# Remove the keys that are not needed for the request
81100
extra_args.pop("messages", None)
82101
extra_args.pop("max_completion_tokens", None)
83102
extra_args.pop("model", None)

0 commit comments

Comments
 (0)