WIP - ai process builder codex attempt
This commit is contained in:
173
backend/src/ai-processes/demo-process.ts
Normal file
173
backend/src/ai-processes/demo-process.ts
Normal file
@@ -0,0 +1,173 @@
|
||||
import { ProcessGraphDefinition } from './ai-processes.types';
|
||||
|
||||
export const demoRegisterNewPetProcess: ProcessGraphDefinition = {
|
||||
id: 'register_new_pet',
|
||||
name: 'Register New Pet',
|
||||
description: 'Resolve account/contact then create pet.',
|
||||
allowCycles: false,
|
||||
nodes: [
|
||||
{
|
||||
id: 'start',
|
||||
type: 'Start',
|
||||
data: { label: 'Start' },
|
||||
},
|
||||
{
|
||||
id: 'decide_account',
|
||||
type: 'LLMDecisionNode',
|
||||
data: {
|
||||
label: 'Decide Account Action',
|
||||
promptTemplate:
|
||||
'Decide whether to find or create an account. Return JSON {"accountAction":"find|create","accountName":"string"}.',
|
||||
inputKeys: ['accountName'],
|
||||
outputSchema: {
|
||||
type: 'object',
|
||||
required: ['accountAction', 'accountName'],
|
||||
properties: {
|
||||
accountAction: { type: 'string', enum: ['find', 'create'] },
|
||||
accountName: { type: 'string' },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
model: { name: 'gpt-4o-mini', temperature: 0 },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'find_account',
|
||||
type: 'ToolNode',
|
||||
data: {
|
||||
label: 'Find Account',
|
||||
toolName: 'findAccount',
|
||||
argsTemplate: { accountName: '{{state.accountName}}' },
|
||||
outputMapping: { accountId: 'accountId', found: 'accountFound' },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'create_account',
|
||||
type: 'ToolNode',
|
||||
data: {
|
||||
label: 'Create Account',
|
||||
toolName: 'createAccount',
|
||||
argsTemplate: { accountName: '{{state.accountName}}' },
|
||||
outputMapping: { accountId: 'accountId' },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'decide_contact',
|
||||
type: 'LLMDecisionNode',
|
||||
data: {
|
||||
label: 'Decide Contact Action',
|
||||
promptTemplate:
|
||||
'Decide whether to find or create a contact. Return JSON {"contactAction":"find|create","firstName":"string","lastName":"string"}.',
|
||||
inputKeys: ['firstName', 'lastName'],
|
||||
outputSchema: {
|
||||
type: 'object',
|
||||
required: ['contactAction', 'firstName', 'lastName'],
|
||||
properties: {
|
||||
contactAction: { type: 'string', enum: ['find', 'create'] },
|
||||
firstName: { type: 'string' },
|
||||
lastName: { type: 'string' },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
model: { name: 'gpt-4o-mini', temperature: 0 },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'find_contact',
|
||||
type: 'ToolNode',
|
||||
data: {
|
||||
label: 'Find Contact',
|
||||
toolName: 'findContact',
|
||||
argsTemplate: {
|
||||
accountId: '{{state.accountId}}',
|
||||
firstName: '{{state.firstName}}',
|
||||
lastName: '{{state.lastName}}',
|
||||
},
|
||||
outputMapping: { contactId: 'contactId', found: 'contactFound' },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'create_contact',
|
||||
type: 'ToolNode',
|
||||
data: {
|
||||
label: 'Create Contact',
|
||||
toolName: 'createContact',
|
||||
argsTemplate: {
|
||||
accountId: '{{state.accountId}}',
|
||||
firstName: '{{state.firstName}}',
|
||||
lastName: '{{state.lastName}}',
|
||||
},
|
||||
outputMapping: { contactId: 'contactId' },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'need_pet',
|
||||
type: 'HumanInputNode',
|
||||
data: {
|
||||
label: 'Collect Pet Info',
|
||||
promptToUser: 'What is the pet name and type?',
|
||||
requiredFieldsSchema: {
|
||||
type: 'object',
|
||||
required: ['petName', 'petType'],
|
||||
properties: {
|
||||
petName: { type: 'string' },
|
||||
petType: { type: 'string' },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'create_pet',
|
||||
type: 'ToolNode',
|
||||
data: {
|
||||
label: 'Create Pet',
|
||||
toolName: 'createPet',
|
||||
argsTemplate: {
|
||||
contactId: '{{state.contactId}}',
|
||||
petName: '{{state.petName}}',
|
||||
petType: '{{state.petType}}',
|
||||
},
|
||||
outputMapping: { petId: 'petId' },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'end',
|
||||
type: 'End',
|
||||
data: { label: 'End' },
|
||||
},
|
||||
],
|
||||
edges: [
|
||||
{ id: 'e_start_account', source: 'start', target: 'decide_account' },
|
||||
{
|
||||
id: 'e_account_find',
|
||||
source: 'decide_account',
|
||||
target: 'find_account',
|
||||
condition: { '==': [{ var: 'accountAction' }, 'find'] },
|
||||
},
|
||||
{
|
||||
id: 'e_account_create',
|
||||
source: 'decide_account',
|
||||
target: 'create_account',
|
||||
condition: { '==': [{ var: 'accountAction' }, 'create'] },
|
||||
},
|
||||
{ id: 'e_account_to_contact', source: 'find_account', target: 'decide_contact' },
|
||||
{ id: 'e_create_account_to_contact', source: 'create_account', target: 'decide_contact' },
|
||||
{
|
||||
id: 'e_contact_find',
|
||||
source: 'decide_contact',
|
||||
target: 'find_contact',
|
||||
condition: { '==': [{ var: 'contactAction' }, 'find'] },
|
||||
},
|
||||
{
|
||||
id: 'e_contact_create',
|
||||
source: 'decide_contact',
|
||||
target: 'create_contact',
|
||||
condition: { '==': [{ var: 'contactAction' }, 'create'] },
|
||||
},
|
||||
{ id: 'e_contact_to_pet', source: 'find_contact', target: 'need_pet' },
|
||||
{ id: 'e_create_contact_to_pet', source: 'create_contact', target: 'need_pet' },
|
||||
{ id: 'e_need_pet_to_create', source: 'need_pet', target: 'create_pet' },
|
||||
{ id: 'e_pet_to_end', source: 'create_pet', target: 'end' },
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user