@positronic/template-new-project 0.0.56 → 0.0.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +4 -4
- package/package.json +1 -1
- package/template/brain.ts +23 -0
- package/template/brains/hello.ts +28 -17
- package/template/docs/brain-dsl-guide.md +38 -0
- package/template/package.json +1 -1
- package/template/runner.ts +24 -0
- /package/template/{esbuild.config.mjs → .positronic/esbuild.config.mjs} +0 -0
package/index.js
CHANGED
|
@@ -53,10 +53,10 @@ module.exports = {
|
|
|
53
53
|
],
|
|
54
54
|
setup: async ctx => {
|
|
55
55
|
const devRootPath = process.env.POSITRONIC_LOCAL_PATH;
|
|
56
|
-
let coreVersion = '^0.0.
|
|
57
|
-
let cloudflareVersion = '^0.0.
|
|
58
|
-
let clientVercelVersion = '^0.0.
|
|
59
|
-
let genUIComponentsVersion = '^0.0.
|
|
56
|
+
let coreVersion = '^0.0.58';
|
|
57
|
+
let cloudflareVersion = '^0.0.58';
|
|
58
|
+
let clientVercelVersion = '^0.0.58';
|
|
59
|
+
let genUIComponentsVersion = '^0.0.58';
|
|
60
60
|
|
|
61
61
|
// Map backend selection to package names
|
|
62
62
|
const backendPackageMap = {
|
package/package.json
CHANGED
package/template/brain.ts
CHANGED
|
@@ -59,6 +59,29 @@ import { components } from './components/index.js';
|
|
|
59
59
|
* },
|
|
60
60
|
* }));
|
|
61
61
|
* ```
|
|
62
|
+
*
|
|
63
|
+
* To add memory (long-term storage with semantic search):
|
|
64
|
+
*
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import { createBrain, defaultTools } from '@positronic/core';
|
|
67
|
+
* import { createMem0Provider, createMem0Tools } from '@positronic/mem0';
|
|
68
|
+
* import { components } from './components/index.js';
|
|
69
|
+
*
|
|
70
|
+
* const memory = createMem0Provider({
|
|
71
|
+
* apiKey: process.env.MEM0_API_KEY!,
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* export const brain = createBrain({
|
|
75
|
+
* components,
|
|
76
|
+
* defaultTools,
|
|
77
|
+
* memory, // All brains now have access to memory
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* // Memory tools (rememberFact, recallMemories) can be added to agents:
|
|
81
|
+
* const memoryTools = createMem0Tools();
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* See docs/memory-guide.md for more details on memory configuration.
|
|
62
85
|
*/
|
|
63
86
|
export const brain = createBrain({
|
|
64
87
|
components,
|
package/template/brains/hello.ts
CHANGED
|
@@ -1,33 +1,44 @@
|
|
|
1
1
|
import { brain } from '../brain.js';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* A simple agent brain that demonstrates the default tools.
|
|
5
|
+
* A simple agent brain that demonstrates the default tools and outputSchema.
|
|
5
6
|
*
|
|
6
7
|
* This brain uses only a system prompt and tools - no explicit user prompt needed.
|
|
7
8
|
* When prompt is omitted, the agent automatically starts with "Begin."
|
|
8
9
|
*
|
|
10
|
+
* The outputSchema ensures the agent returns structured data that gets stored
|
|
11
|
+
* in state.welcome - making it available for subsequent steps.
|
|
12
|
+
*
|
|
9
13
|
* This brain:
|
|
10
14
|
* 1. Uses generateUI to create a form asking for the user's name
|
|
11
15
|
* 2. Waits for the user to submit the form
|
|
12
|
-
* 3.
|
|
13
|
-
* 4.
|
|
16
|
+
* 3. Completes with a structured welcome message (via outputSchema)
|
|
17
|
+
* 4. The follow-up step logs the greeting, demonstrating type inference
|
|
14
18
|
*
|
|
15
19
|
* Run with: px brain run hello
|
|
16
20
|
*/
|
|
17
|
-
export default brain('hello',
|
|
18
|
-
system: `
|
|
19
|
-
|
|
21
|
+
export default brain('hello', {
|
|
22
|
+
system: `
|
|
23
|
+
You are a friendly greeter for the Positronic framework.
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
1. Use generateUI to create a simple, welcoming form that asks for the user's name
|
|
23
|
-
(use a friendly title and a single text input)
|
|
24
|
-
2. After receiving their name, use consoleLog to log a warm, personalized greeting
|
|
25
|
-
3. Use done to complete with an encouraging message about what they can build
|
|
25
|
+
Your job is to welcome new users and make them feel excited about building AI workflows.
|
|
26
26
|
|
|
27
|
-
You have access to these tools
|
|
28
|
-
- generateUI: Create a form to collect the user's name
|
|
29
|
-
- consoleLog: Log messages to the console
|
|
30
|
-
- done: Complete the greeting with a final message`,
|
|
27
|
+
You have access to a few different tools. Use these tools to greet the user and ask them for their name.
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
Once you have the user's name send them a personalized greeting!
|
|
30
|
+
`,
|
|
31
|
+
outputSchema: {
|
|
32
|
+
schema: z.object({
|
|
33
|
+
userName: z.string().describe('The name the user provided'),
|
|
34
|
+
greeting: z.string().describe('A personalized welcome message for the user'),
|
|
35
|
+
}),
|
|
36
|
+
name: 'welcome' as const,
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
.step('Log Welcome', ({ state }) => {
|
|
40
|
+
// TypeScript knows state.welcome has userName and greeting
|
|
41
|
+
console.log('\n✨ ' + state.welcome.greeting);
|
|
42
|
+
console.log(' Welcome aboard, ' + state.welcome.userName + '!\n');
|
|
43
|
+
return state;
|
|
44
|
+
});
|
|
@@ -908,7 +908,9 @@ brain('Research Assistant')
|
|
|
908
908
|
- `system: string` - System prompt for the agent
|
|
909
909
|
- `prompt: string | ((state) => string)` - User prompt (can be a function)
|
|
910
910
|
- `tools: Record<string, ToolDefinition>` - Tools available to the agent
|
|
911
|
+
- `outputSchema: { schema, name }` - Structured output schema (see below)
|
|
911
912
|
- `maxTokens: number` - Maximum tokens for the agent response
|
|
913
|
+
- `maxIterations: number` - Maximum agent loop iterations (default: 100)
|
|
912
914
|
|
|
913
915
|
### Tool Definition
|
|
914
916
|
|
|
@@ -917,6 +919,42 @@ Each tool requires:
|
|
|
917
919
|
- `inputSchema: ZodSchema` - Zod schema for the tool's input
|
|
918
920
|
- `execute: (input) => Promise<any>` - Function to execute when the tool is called
|
|
919
921
|
|
|
922
|
+
### Agent Output Schema
|
|
923
|
+
|
|
924
|
+
Use `outputSchema` to get structured, typed output from agent steps. This generates a terminal tool that the agent must call to complete, ensuring the output matches your schema:
|
|
925
|
+
|
|
926
|
+
```typescript
|
|
927
|
+
brain('Entity Extractor')
|
|
928
|
+
.brain('Extract Entities', {
|
|
929
|
+
system: 'You are an entity extraction assistant.',
|
|
930
|
+
prompt: 'Extract all people and organizations from the provided text.',
|
|
931
|
+
outputSchema: {
|
|
932
|
+
schema: z.object({
|
|
933
|
+
people: z.array(z.string()).describe('Names of people mentioned'),
|
|
934
|
+
organizations: z.array(z.string()).describe('Organization names'),
|
|
935
|
+
confidence: z.number().min(0).max(1).describe('Confidence score'),
|
|
936
|
+
}),
|
|
937
|
+
name: 'entities' as const, // Use 'as const' for type inference
|
|
938
|
+
},
|
|
939
|
+
})
|
|
940
|
+
.step('Use Extracted Data', ({ state }) => {
|
|
941
|
+
// TypeScript knows state.entities has people, organizations, and confidence
|
|
942
|
+
console.log('Found ' + state.entities.people.length + ' people');
|
|
943
|
+
console.log('Found ' + state.entities.organizations.length + ' organizations');
|
|
944
|
+
return {
|
|
945
|
+
...state,
|
|
946
|
+
summary: 'Extracted ' + state.entities.people.length + ' people and ' +
|
|
947
|
+
state.entities.organizations.length + ' organizations',
|
|
948
|
+
};
|
|
949
|
+
});
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
Key points about `outputSchema`:
|
|
953
|
+
- The agent automatically gets a `done` tool that uses your schema
|
|
954
|
+
- The result is stored under `state[name]` (e.g., `state.entities`)
|
|
955
|
+
- Full TypeScript type inference flows to subsequent steps
|
|
956
|
+
- Use `as const` on the name for proper type narrowing
|
|
957
|
+
|
|
920
958
|
## Environment and Pages Service
|
|
921
959
|
|
|
922
960
|
### The `env` Parameter
|
package/template/package.json
CHANGED
package/template/runner.ts
CHANGED
|
@@ -2,6 +2,30 @@ import { BrainRunner } from '@positronic/core';
|
|
|
2
2
|
import { VercelClient } from '@positronic/client-vercel';
|
|
3
3
|
import { google } from '@ai-sdk/google';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The BrainRunner executes brains with the configured client and adapters.
|
|
7
|
+
*
|
|
8
|
+
* To add memory (automatic conversation indexing with Mem0):
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createMem0Provider, createMem0Adapter } from '@positronic/mem0';
|
|
12
|
+
*
|
|
13
|
+
* const provider = createMem0Provider({
|
|
14
|
+
* apiKey: process.env.MEM0_API_KEY!,
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const memoryAdapter = createMem0Adapter({ provider });
|
|
18
|
+
*
|
|
19
|
+
* export const runner = new BrainRunner({
|
|
20
|
+
* adapters: [memoryAdapter],
|
|
21
|
+
* client: new VercelClient(google('gemini-3-pro-preview')),
|
|
22
|
+
* resources: {},
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* The adapter automatically indexes all agent conversations to memory.
|
|
27
|
+
* See docs/memory-guide.md for more details.
|
|
28
|
+
*/
|
|
5
29
|
export const runner = new BrainRunner({
|
|
6
30
|
adapters: [],
|
|
7
31
|
client: new VercelClient(google('gemini-3-pro-preview')),
|
|
File without changes
|