Skip to content

Commit 4999c6b

Browse files
authored
fix(quickjs): prompt improvements (#2564)
prompt improvements
1 parent 50fb8ae commit 4999c6b

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

libs/partners/quickjs/langchain_quickjs/middleware.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,28 @@
4343
Do NOT assume variables, functions, imports, or helper objects from prior `repl` calls are available.
4444
4545
- The REPL executes JavaScript with QuickJS.
46+
- Write ordinary JavaScript assignments like `const users = find_users_by_name(\"alice\")`.
47+
- Use standard property and index access like `users[0]` and `user.id`.
48+
- Use standard JavaScript control flow like `if (...) {{ ... }}`, loops, array methods, and object manipulation.
4649
- Use `print(...)` to emit output. The tool returns printed lines joined with newlines.
4750
- The final expression value is returned only if nothing was printed.
4851
- There is no filesystem or network access unless equivalent foreign functions have been provided.
49-
- Use it for small computations, control flow, JSON manipulation, and calling externally registered foreign functions.
52+
- The REPL can only use built-in JavaScript features and the foreign functions listed below.
53+
- If the task needs multiple foreign function calls, prefer writing one complete JavaScript program instead of splitting the work across multiple `repl` invocations.
54+
- If one foreign function returns an ID or other value that can be passed directly into the next foreign function, trust it and chain the calls instead of stopping to double-check it.
55+
- If you want to inspect an intermediate value, print it inside the same REPL program; otherwise, try to fetch as much information as possible in one program.
56+
- If a listed foreign function is `async`, call it with `await` inside an async IIFE such as:
57+
`(async () => {{
58+
const city = get_city_for_location(1);
59+
const weather = await fetch_weather(city);
60+
print(weather);
61+
}})()`
62+
- Example syntax only - this shows the JavaScript shape, not specific available foreign functions:
63+
`const items = lookup_fn(\"value\");`
64+
`const firstItem = items[0];`
65+
`const itemId = firstItem.id;`
66+
`print(detail_fn(itemId));`
67+
- Use the repl for small computations, collection manipulation, branching, loops, JSON/object reshaping, and calling externally registered foreign functions.
5068
{external_functions_section}
5169
""" # noqa: E501 # preserve prompt text formatting exactly for the model
5270

libs/partners/quickjs/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test = [
5050
]
5151

5252
[tool.uv.sources]
53-
deepagents = { path = "../../deepagents" }
53+
deepagents = { path = "../../deepagents", editable = true }
5454

5555
[tool.uv]
5656
constraint-dependencies = ["urllib3>=2.6.3"]

libs/partners/quickjs/tests/unit_tests/test_system_prompt.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ def test_system_prompt_includes_rendered_foreign_function_docs() -> None:
8181
prompt = middleware._format_repl_system_prompt()
8282
assert "Available foreign functions:" in prompt
8383
assert "```ts" in prompt
84+
assert "prefer writing one complete JavaScript program" in prompt
85+
assert "trust it and chain the calls" in prompt
86+
assert "print it inside the same REPL program" in prompt
87+
assert "async IIFE" in prompt
88+
assert 'const items = lookup_fn("value");' in prompt
8489
assert "function find_users_by_name(name: string): UserLookup[]" in prompt
8590
assert "async function fetch_weather(city: string): Promise<string>" in prompt
8691
assert "Referenced types:" in prompt

libs/partners/quickjs/uv.lock

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

0 commit comments

Comments
 (0)