Several examples assign Agent.create() without awaiting it
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.1k
- Forks
- 492
- Avg merge
- 37m
- Merged PRs (30d)
- 3
Description
Description
Agent.create() is typed and implemented as Promise<SDKAgent>. Two cookbook embedders treat the return value as an agent handle and call .send() / .close() / Symbol.asyncDispose on the promise.
Coding Agent CLI
CodingAgentSession stores the create promise on this.agent: SDKAgent and never awaits it in the constructor or replaceAgent():
https://github.com/cursor/cookbook/blob/main/sdk/coding-agent-cli/src/agent.ts#L80-L88
constructor(options: CodingAgentSessionOptions) {
this.apiKey = options.apiKey
this.cwd = options.cwd
this.force = options.force
this.mode = options.executionMode ?? "local"
this.modelSelection = options.model
this.agent = this.createAgent()
this.agentKey = this.currentAgentKey()
}
https://github.com/cursor/cookbook/blob/main/sdk/coding-agent-cli/src/agent.ts#L230-L235
private async replaceAgent() {
const previousAgent = this.agent
this.agent = this.createAgent()
this.agentKey = this.currentAgentKey()
await previousAgent[Symbol.asyncDispose]()
}
sendPrompt() then does await this.agent.send(...). If this.agent is still a Promise, that is Promise.send, which is not a function.
App Builder project-name helper
The session path already awaits correctly (session.agent = await Agent.create(...)). The project-name path does not:
https://github.com/cursor/cookbook/blob/main/sdk/app-builder/src/lib/app-builder/server.ts#L337-L353
const agent = Agent.create({
apiKey,
model: { id: process.env.CURSOR_PROJECT_NAME_MODEL ?? "composer-2" },
})
try {
const run = await agent.send(buildProjectNamePrompt(context))
// ...
} finally {
agent.close()
}
Expected
Every Agent.create() / Agent.resume() call is awaited before the handle is used, matching the quickstart and getOrCreateAgent().
Suggested fix
- CLI: make
createAgent()async, await it in the constructor (or defer create until firstsendPrompt), and await the new agent inreplaceAgent()before disposing the old one. - App Builder:
const agent = await Agent.create(...)inpromptProjectNameWithXml.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with sdk/coding-agent-cli/src/agent.ts, especially the constructor, createAgent(), replaceAgent(), and sendPrompt(), then inspect sdk/app-builder/src/lib/app-builder/server.ts around promptProjectNameWithXml. Compare these paths with the quickstart and getOrCreateAgent() usage. Done means every Agent.create() or Agent.resume() handle is awaited before send, close, or disposal, including agent replacement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100