Skip to content

Commit b3dfef6

Browse files
author
raidendotai
committed
ts-cua updates+
1 parent d628368 commit b3dfef6

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ kernel invoke python-basic get-page-title --payload '{"url": "https://www.google
124124
kernel invoke python-bu bu-task --payload '{"task": "Compare the price of gpt-4o and DeepSeek-V3"}'
125125

126126
# Typescript + CUA Sample
127-
kernel invoke ts-cua cua-task --payload '{"query": "open hackernews and get the top 5 articles"}'
127+
kernel invoke ts-cua cua-task --payload '{"task": "open hackernews and get the top 5 articles"}'
128128
```
129129

130130
## Sample apps reference
@@ -138,7 +138,7 @@ These are the sample apps currently available when you run `npx @onkernel/create
138138
| **stagehand** | Returns the first result of a specified Google search | Stagehand | `{ query }` |
139139
| **advanced-sample** | Implements sample apps using advanced Kernel configs | n/a |
140140
| **computer-use** | Implements a prompt loop | Anthropic Computer Use API | `{ query }` |
141-
| **cua** | Implements the OpenAI Computer Using Agent (CUA) | OpenAI CUA | `{ query }` |
141+
| **cua** | Implements the OpenAI Computer Using Agent (CUA) | OpenAI CUA | `{ task }` |
142142

143143
## Documentation
144144

templates/typescript/cua/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ if (!process.env.OPENAI_API_KEY) throw new Error('OPENAI_API_KEY is not set');
1515
* Example app that run an agent using openai CUA
1616
* Args:
1717
* ctx: Kernel context containing invocation information
18-
* payload: An object with a `query` property
18+
* payload: An object with a `task` property
1919
* Returns:
20-
* An answer to the query, elapsed time and optionally the messages stack
20+
* An answer to the task, elapsed time and optionally the messages stack
2121
* Invoke this via CLI:
2222
* export KERNEL_API_KEY=<your_api_key>
2323
* kernel deploy index.ts -e OPENAI_API_KEY=XXXXX --force
24-
* kernel invoke ts-cua cua-task -p "{\"query\":\"current market price range for a used dreamcast\"}"
24+
* kernel invoke ts-cua cua-task -p "{\"task\":\"current market price range for a used dreamcast\"}"
2525
* kernel logs ts-cua -f # Open in separate tab
2626
*/
2727

2828
interface CuaInput {
29-
query: string;
29+
task: string;
3030
}
3131

3232
interface CuaOutput {
@@ -47,28 +47,28 @@ app.action<CuaInput, CuaOutput>(
4747
kernelBrowser.browser_live_view_url,
4848
);
4949

50-
if (!payload?.query){
51-
throw new Error('query is required');
50+
if (!payload?.task){
51+
throw new Error('task is required');
5252
}
5353

5454
try {
5555

5656
// kernel browser
5757
const { computer } = await computers.create({
58-
type: "kernel",
58+
type: "kernel", // for local testing before deploying to Kernel, you can use type: "local"
5959
cdp_ws_url: kernelBrowser.cdp_ws_url,
6060
});
6161

6262
// setup agent
63-
const agent = new Agent(
64-
"computer-use-preview",
63+
const agent = new Agent({
64+
model: "computer-use-preview",
6565
computer,
66-
[], // additional tools
67-
(message: string) => {
66+
tools: [], // additional function_call tools to provide to the llm
67+
acknowledge_safety_check_callback: (message: string) => {
6868
console.log(`> safety check: ${message}`);
6969
return true; // Auto-acknowledge all safety checks for testing
7070
},
71-
);
71+
});
7272

7373
// start agent run
7474
const response = await agent.runFullTurn({
@@ -83,7 +83,7 @@ app.action<CuaInput, CuaOutput>(
8383
content: [
8484
{
8585
type: "input_text",
86-
text: payload.query,
86+
text: payload.task,
8787
// text: "go to https://news.ycombinator.com , open top article , describe the target website design (in yaml format)"
8888
},
8989
],

templates/typescript/cua/lib/agent.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ export class Agent {
4747
private show_images: boolean;
4848
private acknowledge_safety_check_callback: AcknowledgeSafetyCheckCallback;
4949

50-
constructor(
51-
model: string = "computer-use-preview",
52-
computer: BasePlaywrightComputer | null = null,
53-
tools: Tool[],
54-
acknowledge_safety_check_callback: AcknowledgeSafetyCheckCallback = () =>
55-
true,
56-
) {
50+
constructor({
51+
model = "computer-use-preview",
52+
computer = null,
53+
tools = [],
54+
acknowledge_safety_check_callback = () => true,
55+
}: {
56+
model?: string;
57+
computer?: BasePlaywrightComputer | null;
58+
tools?: Tool[];
59+
acknowledge_safety_check_callback?: AcknowledgeSafetyCheckCallback;
60+
}) {
5761
this.model = model;
5862
this.computer = computer;
5963
this.tools = [...toolset.shared, ...tools];

0 commit comments

Comments
 (0)