示例库
仓库 examples/ 目录下有 24 个可运行示例:4 个语言特性示例 + 20 个办公场景示例,全部通过 flow check。每个示例的完整源码都内联在本页(默认折叠,点击展开),无需再翻仓库;examples/dist/ 是办公场景示例编译出的受限 JavaScript。
node packages/cli/dist/main.js check examples/delivery.flow
node packages/cli/dist/main.js run examples/simple.flow \
--input '{"text": "hello agent flow"}'
语言特性示例
simple.flow — 最小 workflow
单个 agent 调用,请求 → 回答
查看完整代码
workflow hello(input: Request) -> Result {
use agent "writer" as writer
type Request {
text: text
}
type Result {
answer: text
}
pipeline {
stage answer -> Result {
return agent(writer) {
task "Answer the request"
input {
request: input
}
tools none
expect Result
}
}
return answer
}
}
parallel.flow — 并发执行 backlog
parallel map + limit 并发实现 backlog,team.member(feature.owner) 动态目标
查看完整代码
workflow build_features(input: Backlog) -> Bundle {
use team "feature-team" as features
type Feature {
id: text
owner: member<features>
brief: text
}
type Backlog {
features: Feature[1..4]
}
type Change {
feature_id: text
summary: text
}
type Bundle {
changes: Change[]
review: text
}
limits {
concurrency: 3
agent_runs: 10
duration: 10m
}
pipeline deliver {
stage changes -> Change[] {
return parallel map input.features as feature limit 2 {
agent(features.member(feature.owner)) {
task "Implement the feature"
input {
feature
}
tools [read_file, write_file]
expect Change
timeout 5m
}
}
}
stage review(changes) -> text {
return agent(features.main) {
task "Review all changes and produce a verdict"
input {
changes
}
tools [read_file]
expect text
}
}
return {
changes
review
}
}
}
verify.flow — 并行检查与闸门
verify 并行检查组(测试 + 评审),pass when Runtime 判定,require 闸门
查看完整代码
workflow guarded_change(input: ChangeRequest) -> Outcome {
use agent "implementer" as implementer
use agent "tester" as tester
use agent "reviewer" as reviewer
type ChangeRequest {
requirement: text
}
type Implementation {
files: path[]
summary: text
}
type TestReport {
passed: bool
command: text
}
type ReviewReport {
blockers: text[]
}
type Outcome {
passed: bool
summary: text
}
pipeline {
stage implement -> Implementation {
return agent(implementer) {
task "Implement the requirement"
input {
requirement: input.requirement
}
tools [read_file, write_file, exec]
expect Implementation
timeout 10m
}
}
stage verification(implement) -> bool {
let result = verify {
parallel {
check tests = agent(tester) {
task "Run the test suite"
input {
implement
}
tools [read_file, exec]
expect TestReport
}
check review = agent(reviewer) {
task "Review for correctness and risk"
input {
implement
}
tools [read_file]
expect ReviewReport
}
}
pass when
tests.passed
and review.blockers.empty
}
require result.passed
else fail "verification failed"
return result.passed
}
return {
passed: verification
summary: implement.summary
}
}
}
delivery.flow — 旗舰示例
计划拆解 → 并行执行(disjoint 写范围互斥)→ 测试 → 安全评审
查看完整代码
workflow deliver_change(input: ChangeRequest) -> Delivery {
use team "engineering-team" as engineering
use agent "secure-code-reviewer" as security
limits {
concurrency: 4
agent_runs: 12
duration: 30m
}
type WorkItem {
id: text
owner: member<engineering>
objective: text
writes: path[]
acceptance: text[]
}
type Plan {
summary: text
work: WorkItem[1..6]
}
type ChangeResult {
work_id: text
changed_files: path[]
summary: text
evidence: text[]
}
type TestResult {
passed: bool
command: text
summary: text
}
type ReviewResult {
blockers: text[]
warnings: text[]
}
type Delivery {
summary: text
changes: ChangeResult[]
tests: TestResult
review: ReviewResult
}
pipeline delivery {
stage plan -> Plan {
let result = agent(engineering.main) {
task """
Analyze the requirement and the current project.
Split the work into well-scoped, independently completable work items.
Do not modify files.
"""
input {
request: input.request
project: context.project
}
tools [read_file, list_dir, grep]
expect Plan
timeout 5m
}
require result.work.count in 1..6
else fail "plan must contain 1 to 6 work items"
require unique(result.work[*].id)
else fail "work item ids must be unique"
require disjoint(result.work[*].writes)
else fail "parallel work items must not have overlapping write scopes"
emit progress {
phase: "plan"
message: result.summary
}
return result
}
stage changes(plan) -> ChangeResult[] {
return parallel map plan.work as item limit 4 {
agent(engineering.member(item.owner)) {
task """
Complete the current work item.
Only modify files under the declared writes paths.
Return the changed files, an implementation summary and acceptance evidence.
"""
input {
request: input.request
work: item
}
tools [
read_file,
list_dir,
grep,
write_file,
edit_file,
apply_patch,
exec
]
write item.writes
expect ChangeResult
timeout 10m
retry {
attempts: 1
on: [timeout, rate_limit]
}
}
}
}
stage verification(plan, changes) -> Verification {
let result = verify {
parallel {
check tests = agent(
engineering.member("test-engineer")
) {
task """
Execute real tests against the acceptance criteria.
Do not modify product code.
"""
input {
plan
changes
}
tools [
read_file,
list_dir,
grep,
exec
]
expect TestResult
timeout 10m
}
check security = agent(security) {
task """
Review the changes for security, architectural boundaries and privilege escalation risks.
"""
input {
plan
changes
}
tools [
read_file,
list_dir,
grep
]
expect ReviewResult
timeout 8m
}
}
pass when
tests.passed
and security.blockers.empty
}
return result
}
require verification.passed
else fail "final verification failed"
stage summary(
plan,
changes,
verification
) -> text {
return agent(engineering.main) {
task """
Produce a concise delivery summary from the execution results.
Do not alter test results or hide risks.
"""
input {
plan
changes
verification
}
tools none
expect text
}
}
return {
summary
changes
tests: verification.checks.tests
review: verification.checks.security
}
}
}
沟通与记录
email-triage.flow — 邮件分流与回复草拟
parallel map + limit 4、if/else 双路 emit progress
查看完整代码
// 场景: 批量分流收件箱邮件,分类并标记垃圾邮件,对需要回复的邮件逐封草拟回复
workflow triage_inbox(input: InboxSnapshot) -> TriageResult {
use agent "mail-assistant" as assistant
type Email {
id: text
from: text
subject: text
body: text
}
type InboxSnapshot {
mailbox: text
emails: Email[1..20]
}
type ClassifiedEmail {
id: text
category: text
needs_reply: bool
reason: text
}
type Draft {
email_id: text
to: text
body: text
}
type TriageSummary {
total: number
spam_count: number
urgent_count: number
}
type TriageResult {
mailbox: text
classified: ClassifiedEmail[]
drafts: Draft[]
summary: TriageSummary
}
limits {
concurrency: 4
agent_runs: 45
duration: 20m
}
pipeline triage {
stage classify -> ClassifiedEmail[] {
let items = parallel map input.emails as item limit 4 {
agent(assistant) {
task """
Classify one email from the inbox snapshot.
Pick exactly one category: urgent, normal or spam. Mark needs_reply
true only when the sender explicitly waits for an answer. Give a
one sentence reason quoting the decisive cue.
"""
input {
email: item
}
tools none
expect ClassifiedEmail
timeout 2m
retry { attempts: 1 on: [transient] }
}
}
require unique(items[*].id)
else fail "classified ids must stay unique"
emit progress {
phase: "classify"
mailbox: input.mailbox
total: items.count
}
return items
}
stage drafts(classify) -> Draft[] {
let replies = agent(assistant) {
task """
Draft polite replies for the emails classified with needs_reply true.
Return exactly one draft per such email and none for the others.
Keep each reply under 150 words and reuse the language of the sender.
"""
input {
emails: input.emails
classified: classify
}
tools none
expect Draft[]
timeout 6m
}
require replies.count <= classify.count
else fail "cannot draft more replies than classified emails"
require unique(replies[*].email_id)
else fail "at most one reply per email"
return replies
}
stage summary(classify, drafts) -> TriageSummary {
let stats = agent(assistant) {
task """
Summarize the triage run. total is the number of classified emails,
spam_count how many were marked spam, urgent_count how many urgent.
Count strictly from the classified list, do not guess.
"""
input {
classified: classify
drafted: drafts
}
tools none
expect TriageSummary
timeout 2m
}
require stats.total == classify.count
else fail "summary total must match the classified emails"
return stats
}
if summary.urgent_count > 0 {
emit progress {
phase: "done"
mailbox: input.mailbox
attention: true
urgent: summary.urgent_count
}
} else {
emit progress {
phase: "done"
mailbox: input.mailbox
attention: false
urgent: summary.urgent_count
}
}
return {
mailbox: input.mailbox
classified: classify
drafts: drafts
summary: summary
}
}
}
meeting-notes.flow — 会议纪要与行动项
parallel 双分支、member<ops> 行动项归属
查看完整代码
// 场景: 把会议逐字稿蒸馏成结构化纪要,提取指派到人的行动项,并草拟跟进邮件
workflow write_minutes(input: MeetingRecord) -> Minutes {
use team "ops-team" as ops
type Attendee {
name: text
role: text
}
type MeetingRecord {
title: text
date: text
transcript: text
attendees: Attendee[2..12]
}
type Condensed {
summary: text
highlights: text[]
}
type ActionItem {
description: text
owner: member<ops>
due: text
}
type Digest {
summary: text
highlights: text[]
actions: ActionItem[]
}
type Minutes {
title: text
date: text
summary: text
highlights: text[]
actions: ActionItem[]
followup_email: text
}
limits {
concurrency: 2
agent_runs: 6
duration: 15m
}
pipeline minutes {
stage digest -> Digest {
let parts = parallel {
condensed = agent(ops.main) {
task """
Distill the meeting transcript. summary is a five sentence recap of
the decisions and their context. highlights lists the two to five
most important outcomes, one line each.
"""
input {
meeting: input
}
tools none
expect Condensed
timeout 5m
}
actions = agent(ops.main) {
task """
Extract the action items agreed in the meeting. Each item names one
concrete deliverable, its owner as a team member id among the
attendees, and a due date as stated, or the words "not stated".
Skip vague intentions without an owner.
"""
input {
meeting: input
}
tools none
expect ActionItem[]
timeout 5m
}
}
require parts.actions.count in 0..8
else fail "keep the action list focused, at most 8 items"
emit progress {
meeting: input.title
actions: parts.actions.count
}
return {
summary: parts.condensed.summary
highlights: parts.condensed.highlights
actions: parts.actions
}
}
stage followup(digest) -> text {
let email = agent(ops.main) {
task """
Write the follow-up email for the meeting. Thank the attendees,
restate each action item with its owner and due date as a checklist,
and close with where to raise questions. Plain text, no markdown.
"""
input {
meeting: input
minutes: digest
}
tools none
expect text
timeout 4m
}
return email
}
return {
title: input.title
date: input.date
summary: digest.summary
highlights: digest.highlights
actions: digest.actions
followup_email: followup
}
}
}
weekly-report.flow — 团队周报汇总
pipeline 级 verify + require passed、union(投影).empty
查看完整代码
// 场景: 把团队成员的零散周更新结构化,汇总亮点与风险,经质量闸门后生成周报
workflow compile_weekly_report(input: TeamUpdates) -> WeeklyReport {
use agent "team-assistant" as assistant
type MemberUpdate {
member: text
notes: text
blockers: text[]
}
type TeamUpdates {
week: text
members: MemberUpdate[1..10]
}
type StructuredUpdate {
member: text
done: text[]
planned: text[]
blockers: text[]
}
type HighlightList {
items: text[]
}
type RiskList {
items: text[]
}
type WeeklyReport {
week: text
by_member: StructuredUpdate[]
highlights: text[]
risks: text[]
narrative: text
}
limits {
concurrency: 5
agent_runs: 15
duration: 15m
}
pipeline weekly {
stage collect -> StructuredUpdate[] {
let updates = parallel map input.members as item {
agent(assistant) {
task """
Structure one member's raw weekly notes. done lists shipped work,
planned lists next week's commitments, blockers lists impediments
needing help. Use the member's own words where possible and never
invent work items.
"""
input {
member: item
}
tools none
expect StructuredUpdate
timeout 2m
retry { attempts: 1 on: [transient] }
}
}
return updates
}
stage narrative(collect) -> text {
let story = agent(assistant) {
task """
Write the narrative body of the weekly report: two short paragraphs
for management, progress first, then risks and asks. Base every
sentence on the structured updates.
"""
input {
week: input.week
updates: collect
}
tools none
expect text
timeout 4m
}
return story
}
let quality = verify {
check highlights = agent(assistant) {
task """
From all structured updates extract the week's key achievements.
Two to five items, one line each, outcomes rather than activities.
"""
input {
updates: collect
}
tools none
expect HighlightList
timeout 3m
}
check risks = agent(assistant) {
task """
Aggregate every blocker into the risk list: merge duplicates, name
the affected members and the help needed. Produce at least one entry
whenever any blocker exists.
"""
input {
updates: collect
}
tools none
expect RiskList
timeout 3m
}
pass when highlights.items.any and (risks.items.any or union(collect[*].blockers).empty)
}
require quality.passed
else fail "weekly report must surface highlights, and risks whenever blockers exist"
return {
week: input.week
by_member: collect
highlights: quality.checks.highlights.items
risks: quality.checks.risks.items
narrative: narrative
}
}
}