Skip to content

Commit 6dc8403

Browse files
authored
Merge pull request #10 from plotday/fix/generate
Fixed to "plot agent generate"
2 parents ceecf33 + 8a32964 commit 6dc8403

6 files changed

Lines changed: 35 additions & 18 deletions

File tree

.changeset/afraid-frogs-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plotday/sdk": patch
3+
---
4+
5+
Changed: Add instructions to AGENTS.md to avoid accidentally reprocessing agent-created activities

.changeset/grumpy-bikes-prove.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plotday/sdk": patch
3+
---
4+
5+
Fixed: Set displayName on plot agent generate

.changeset/tidy-pumas-hammer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plotday/sdk": patch
3+
---
4+
5+
Changed: Generate a plotAgentId on "plot agent generate" if none specified

sdk/cli/commands/deploy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface PackageJson {
3333
}
3434

3535
interface AgentSource {
36+
displayName: string;
3637
dependencies: Record<string, string>;
3738
files: Record<string, string>;
3839
}

sdk/cli/commands/generate.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface GenerateOptions {
1515
}
1616

1717
interface AgentSource {
18+
displayName: string;
1819
dependencies: Record<string, string>;
1920
files: Record<string, string>;
2021
}
@@ -98,13 +99,9 @@ export async function generateCommand(options: GenerateOptions) {
9899
}
99100
}
100101

101-
// Require agent ID
102+
// Generate agent ID if not provided
102103
if (!agentId) {
103-
out.error(
104-
"Agent ID is required",
105-
"Run 'plot agent create' to generate one, or provide --id flag"
106-
);
107-
process.exit(1);
104+
agentId = crypto.randomUUID();
108105
}
109106

110107
// Load DEPLOY_TOKEN from multiple sources
@@ -236,6 +233,7 @@ export async function generateCommand(options: GenerateOptions) {
236233
const packageJson = {
237234
name: agentId,
238235
version: "1.0.0",
236+
displayName: source.displayName,
239237
plotAgentId: agentId,
240238
dependencies: source.dependencies,
241239
};
@@ -271,11 +269,7 @@ export async function generateCommand(options: GenerateOptions) {
271269
"utf-8"
272270
);
273271
// Replace template variables
274-
const displayName = packageJson.name
275-
.split("-")
276-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
277-
.join(" ");
278-
readmeTemplate = readmeTemplate.replace(/\{\{displayName\}\}/g, displayName);
272+
readmeTemplate = readmeTemplate.replace(/\{\{displayName\}\}/g, source.displayName);
279273
readmeTemplate = readmeTemplate.replace(/\{\{packageManager\}\}/g, "pnpm");
280274
writeFile(readmePath, readmeTemplate);
281275

sdk/src/agents-guide.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Plot agents are TypeScript classes that extend the \`Agent\` base class. Agents
2020
**Critical**: All agent and tool functions are executed in a sandboxed, ephemeral environment with limited resources:
2121
2222
- **Memory is temporary**: Anything stored in memory (e.g. as a variable in the agent/tool object) is lost after the function completes. Use the Store tool instead. Only use memory for temporary caching.
23-
- **Limited CPU time**: Each execution has limited CPU time (typically 10 seconds) and memory (128MB)
24-
- **Use the Run tool**: Queue separate chunks of work with \`run.now(functionName, context)\`
25-
- **Break long operations**: Split large operations into smaller batches that can be processed independently
23+
- **Limited resources**: Each execution has limited CPU time and memory
24+
- **Limited runtime**: Agents execute in a Cloudflare Worker environment with the \`nodejs_compat\` flag. This means many but not all Node.js APIs are available.
25+
- **Use the Run tool**: Split large operations into smaller batches with \`run.now(functionName, context)\`
2626
- **Store intermediate state**: Use the Store tool to persist state between batches
2727
- **Examples**: Syncing large datasets, processing many API calls, or performing batch operations
2828
@@ -46,13 +46,17 @@ export default class MyAgent extends Agent {
4646
// Store, Run, and Callback methods are available directly via this
4747
}
4848
49-
async activate(priority: Pick<Priority, "id">) {
49+
async activate(priority) {
5050
// Called when agent is enabled for a priority
5151
// Common actions: request auth, create setup activities
5252
}
5353
54-
async activity(activity: Activity) {
55-
// Called when an activity is routed to this agent
54+
async activity(activity, changes) {
55+
// Called when an activity is created or updated in the priority
56+
// where this agent is added (or its child priorities).
57+
//
58+
// IMPORTANT: check that changes is null if you only want to process new activities
59+
//
5660
// Common actions: process external events, update activities
5761
}
5862
}
@@ -62,7 +66,7 @@ export default class MyAgent extends Agent {
6266
6367
### Accessing Tools
6468
65-
All tools are accessed through the \`tools\` parameter in the constructor:
69+
Tools are made available through the \`tools\` parameter in the constructor:
6670
6771
\`\`\`typescript
6872
constructor(protected tools: Tools) {
@@ -72,6 +76,7 @@ constructor(protected tools: Tools) {
7276
\`\`\`
7377
7478
All \`tools.get()\` calls must occur in the constructor as they are used for dependency analysis.
79+
Assign tool instances to class properties for use in other methods.
7580
7681
### Built-in Tools (Always Available)
7782
@@ -473,6 +478,8 @@ try {
473478
6. **Clean up callbacks and stored state** - Delete callbacks and Store entries when no longer needed.
474479
7. **Handle missing auth gracefully** - Check for stored auth before operations.
475480
8. **Batch size matters** - Process enough items per batch to be efficient, but few enough to stay under time limits.
481+
9. **Processing self-created activities** - Other users may change an Activity created by the agent, resulting in an \`activity\` call.
482+
Be sure to check the \`changes\` parameter and/or \`activity.author\` to avoid re-processing.
476483
477484
## Type Patterns
478485

0 commit comments

Comments
 (0)