CangjieMagic:基于仓颉语言的Agent开发框架实践
如果无法正常显示,请先停止浏览器的去广告插件。
1.
2. 01 基于 CangjieMagic 构建 Agent 应用示例
02 框架能力拆解:Cangjie Magic 如何支持高效 Agent 构建
03 技术基础:仓颉语言对 Agent 开发的原生支撑
04 仓颉语言在其他 AI 方向上的探索
3.
4. 01
5. @agent[
model: "deepseek:deepseek-chat",
Markdownify MCP Server
executor: "plan-react",
mcp: [
stdio("node ${MARKDOWNIFY_DIR}/dist/index.js"),
stdio("docker run mcp/filesystem ...")
添加 MCP 服务器
]
]
Filesystem MCP Server
class FileAssistant {
@prompt[pattern: ERA] (
expectation: "Follow遵从指导逐步完成任务",
role: "嘿,伙计!你是一个文件小助理",
action: "对用户问题,仔细规划,然后使用工具,例如..." )
}
6. “
"
let agent = FileAssistant()
for (data in agent.asyncChat(input)) {
print(data)
}
Plan
Divide subtasks
Reason
Execution
Select
tool
Summarize
Invoke
tool
…
…
“
, …
…"
7. “
PC
…
…
…
class ConsolePrinter <: TagStreamVisitor {
override protected func onTag(tag: String) {
Console.stdOut.writeln(tag)
}
override protected func onChunk(chunk:
String) {
Console.stdOut.write(chunk)
}
…
}
8. "
@agent[
model: "deepseek:deepseek-chat",
executor: "naive",
rag: {
source: "./docs/tutorial.md",
mode: "static"
}
]
class QABot {
@prompt[pattern: ERA] (
expectation: "代码段使用
```cangjie 和 ```修饰",
role: "你是 QA 小能手",
action: "检索文档并回复问题"
)
}
"
let agent = QABot()
for (data in agent.asyncChat(input))
{
print(data)
}
9. "
let group = DispatchAgent() <= [
FileAssistant(),
QABot(),
...
]
"
for (data in group.asyncChat(input))
{
print(data)
}
...
•
•
10. 02
11. •
•
Agent
•
•
•
•
|
|
|
|
|
|
|
|
•
,
,
12. @agent[
model: "openai:gpt-4o",
reason: "react“
tools: [search,
BarAgent().asTool(),
VectorDB().asRetriever()],
mcp: [
{name: “docker”, args:["mcp/filesystem"]}
]
]
class Foo {
@prompt[pattern: ERP](
expectation: "
role: "
",
action: "
"
)
}
",
let linearGroup: LinearGroup = ag1 |> ag2 |> ag3
Agent
let leaderGroup: LeaderGroup = ag1 <= [ag2, ag3]
Agent
Agent
let freeGroup: FreeGroup = ag1 | ag2 | ag3
Agent
13. @tool[description: "
parameters:{ q: "
" } ]
func search(q: String):String { … }
",
•
•
•
@agent[
tools: [search,
BarAgent().asTool(),
VectorDB().asRetriever()],
mcp: [
{name: “docker”, args: ["mcp/filesystem"]}
]
]
class Foo { ... }
|
14. •
•
•
*
@agent[
executor: "react"
]
class Foo { … }
…
…
… …
-
@agent
class Foo {
@execution(
while ($incomplete) {
think |> act
}
)
}
•
•
Think
CoT ReAct …
Act
…
15. Agent
@conversation[agent: FooAgent()] (
"明天上海天气" -> weather
println(weather)
"给我出行建议" -> suggestion
println(suggestion)
)
@agent[memory: true]
class FooAgent {
...
}
let agent = FooAgent()
let weather = agent.chat(“明天上海天气")
:
RAG
embedding
•
•
•
Agent
•
16. @agent[
model: “myModel”,
executor: “myExecutor”,
retriever: “myRetriever”
]
class Foo { … }
•
•
@chatModel[
name: “myModel”,
]
class MyModel {
func chat(request: ChatRequest) { … }
}
@executorl[
name: “myExecutor”,
]
class MyExecutor {
func execute(agent: Agent, request: AgentRequest { … }
}
@retriever[
name: “myRetriever”,
]
class MyRetriever {
func search(query: String): Array<Document> {… }
}
17. 03
18. Cangjie
TypeInfo.of(Cangjie) != “Chinese PL.”
Memory
enum SupportedOS {
| HarmonyOS | Linux
| Windows | MacOS
| NextOne
}
Tools
// Run
// Develop
// (TBD)
!
•
•
•
•
•
•
•
•
LLM Powered Autonomous Agents | Lil'Log (lilianweng.github.io)
…
18
19. ...
@agent class TravelRouteAgent {
@prompt(pattern: APE]{
action:"帮助用户制定旅行路线",
purpose:"让用户在计划时间内多参观景点并得到充分休息”,
expectation:"生成一条合理的旅游条点路线,包括时间、景点、通勤等信息”
}
}
OO
/
2.
3.
”
20. @agent[
model: "deepseek:deepseek-chat",
executor: "plan-react",
mcp: [
stdio("node ${MARKDOWNIFY_DIR}/dist/index.js"),
stdio("docker run mcp/filesystem ...")
]
类型系统
]
class FileAssistant {
元编程
@prompt[pattern: ERA] (
expectation: "Follow instructions to complete tasks
step by step",
role: "You are a file assistant, helping users manage files",
action: "For each request, plan step by step.
You can use tools such as..." )
}
|>
|>
自然语言
<= [
]
LLM
|
|
Agent
21. X
=
22. 04
23. 仓颉
• 各类应用场景分布均衡 • 部分应用场景数据缺失
• 自然语言 代码对数据较多 • 自然语言 代码对数据很少
24. •
•
•
•
25. ⚫
⚫
→
⚫
➢
➢
⚫
→
→
26. ⚫
⚫
⚫
27. 。
⚫
⚫
⚫
•
•
•
•
•
•
•
•
•
•
•
•
•
16
Minhash
•
➢
➢
➢
➢
•
•
•
•
28. ⚫
⚫
⚫
(
)
(
)
(
)
29. 核心思想:通过在
⚫
⚫
⚫
➢
➢
中补充额外信息来提升生成效果,并对低质量的结果进行过滤
30. 线下指标
线上指标
评测接纳率
代码接受率
31. Cangjie Magic开源项目
32.
33.
34.