-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy path20-constrained-transitions.ts
More file actions
86 lines (77 loc) · 2.73 KB
/
Copy path20-constrained-transitions.ts
File metadata and controls
86 lines (77 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Constrained Speaker Transitions -- control which agents can follow which.
*
* Demonstrates `allowedTransitions` which restricts which agent can
* speak after which. Useful for enforcing conversational protocols.
*
* In this example, a code review workflow enforces:
* - developer can only be followed by reviewer
* - reviewer can only be followed by developer or approver
* - approver can only be followed by developer (for revisions)
*
* Requirements:
* - Conductor server with LLM support
* - AGENTSPAN_SERVER_URL=http://localhost:8080/api as environment variable
* - AGENTSPAN_LLM_MODEL=openai/gpt-4o-mini as environment variable
*/
import { Agent, AgentRuntime } from '@io-orkes/conductor-javascript/agents';
import { llmModel } from './settings';
export const developer = new Agent({
name: 'developer',
model: llmModel,
instructions:
'You are a software developer. Write or revise code based on feedback. ' +
'Keep responses focused on code changes.',
});
export const reviewer = new Agent({
name: 'reviewer',
model: llmModel,
instructions:
"You are a code reviewer. Review the developer's code for bugs, style, " +
'and best practices. Provide specific, actionable feedback.',
});
export const approver = new Agent({
name: 'approver',
model: llmModel,
instructions:
'You are the tech lead. Review the code and feedback. Either approve ' +
'the code or request revisions with specific guidance.',
});
// Constrained transitions enforce a review protocol:
// developer -> reviewer (code must be reviewed)
// reviewer -> developer OR approver (send back for fixes or escalate)
// approver -> developer (request revisions)
export const codeReview = new Agent({
name: 'code_review',
model: llmModel,
agents: [developer, reviewer, approver],
strategy: 'round_robin',
maxTurns: 6,
allowedTransitions: {
developer: ['reviewer'],
reviewer: ['developer', 'approver'],
approver: ['developer'],
},
});
// -- Run -------------------------------------------------------------------
async function main() {
const runtime = new AgentRuntime();
try {
const result = await runtime.run(
codeReview,
'Write a Python function to validate email addresses using regex.',
);
result.printResult();
// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(codeReview);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples --agents code_review
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(codeReview);
} finally {
await runtime.shutdown();
}
}
main().catch(console.error);