Skip to content
中文

StepOutcome ​

CORE · type · Type contract

Decision a step returns to the engine.

Import ​

ts
import type { StepOutcome } from '@jangts/agent-core/engine';
js
/** @typedef {import('@jangts/agent-core/engine').StepOutcome} StepOutcome */

Other public entry points:@jangts/agent-core, @jangts/agent-core/engine, @jangts/agent-core/types, @jangts/agent-core/structs.

Definition ​

Type: StepOutcome<Value>

Type parameters ​

Type parameterConstraintDefault type
Value——

Union branch structure ​

Optional shapes of StepOutcome: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
type"continue"RequiredRead-only. See the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
type"complete"RequiredRead-only. See the type definition and usage context.
valueValueRequiredRead-only. See the type definition and usage context.

Examples ​

A single ordinary step is enough to run ​

Beginner · Node.js

ts
import { AgentCoreEngine } from '@jangts/agent-core/engine';

const agent = new AgentCoreEngine<string>();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);
js
import { AgentCoreEngine } from '@jangts/agent-core/engine';
const agent = new AgentCoreEngine();
const answer = await agent.run(() => ({ type: 'complete', value: '你好,Core' }));
console.log(answer);

Add an explicit Workflow and still call run ​

Configuration · Node.js

ts
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';

type State = { name: string; answer?: string };
const workflow = defineWorkflow<State, string>({
  id: 'greeting',
  nodes: [{
    id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
    run: state => ({ answer: '你好,' + state.name }),
    routes: [route.deliver('answer')],
  }],
});

const agent = new AgentCoreEngine({ workflow });
console.log(await agent.run({ name: 'Ivan' }));
console.log(await agent.run({ name: '访客' }));
js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({
    id: 'greeting',
    nodes: [{
            id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
            run: state => ({ answer: '你好,' + state.name }),
            routes: [route.deliver('answer')],
        }],
});
const agent = new AgentCoreEngine({ workflow });
console.log(await agent.run({ name: 'Ivan' }));
console.log(await agent.run({ name: '访客' }));

API reference, usage examples and developer guides.