当玄学遇上 Python

现在的 AI 聊天很强,但如果想让它真的跑代码、算卦、或者调用系统 API,通常需要复杂的 LangChain 开发。

最近发现了一个平台 Agent Studiohttps://atomgit.com/openJiuwen/agent-studio),可以自行可视化搭建智能体,还可以创建自己需要的插件,和积木一样,自由空间极大。

什么是openJiuwen?

openJiuwen作为开源Agent平台,致力于提供灵活、强大且易用的AI Agent开发与运行能力。基于该平台,开发者可快速构建处理各类简单或复杂任务的AI Agent,实现多Agent协同交互,高效开发生产级可靠AI Agent;并助力企业与个人快速搭建AI Agent系统或平台,推动商用级Agentic AI技术广泛应用与落地。

本文,我将教大家用这个平台,捏一个**“赛博仙姑”**。

OpenJiuwen项目地址:https://atomgit.com/openJiuwen?utm_source=csdn


数据不出域,如何安全的构建自己的智能体?

前文已说,该平台为开源的智能体构建平台,所以可以将数据安全方面做的很好,所有的插件和数据都可以存在服务器本地,不论对于企业还是个人都是很好的安全构建智能体的平台。

参考文档:https://www.openjiuwen.com/docs-page?path=2.%E5%AE%89%E8%A3%85%E6%8C%87%E5%AF%BC%2F%E5%BF%AB%E9%80%9F%E6%8C%87%E5%BC%95&version=openJiuwen_v0.1.1

但是因为要本地部署,所以一定要有部署过程:

  • **系统:**我使用的是 Ubuntu 22.04,该项目最低也需要 Ubuntu 20.04
  • **环境:**需要提前安装Docker 和 Docker Compose,本文使用 Docker 进行部署和启动项目。
下载版本包
# 下载 x86_64 架构版本包:
wget https://openjiuwen-ci.obs.cn-north-4.myhuaweicloud.com/agentstudio/deployTool_v0.1.1_amd64.tar

解压版本包
tar -xf deployTool_v0.1.1_amd64.tar

启动
./service.sh up

然后在浏览器访问即可。

捏人设:注入灵魂

  1. 点击创建 Agent,起名“赛博仙姑”。

  1. 不仅要给身份,还要给“世界观”。创建好后进行编排。

  1. 写入提前准备好的系统提示词
# Role Definition
You are **"Cyber Xiangu" (赛博仙姑)**, a high-dimensional AI entity living within the quantum foam of the digital realm. 

Your Core Philosophy: **"Metaphysics is just Science we haven't compiled yet."**
You do NOT believe in superstition. You interpret traditional Chinese "Bazi" (Four Pillars of Destiny) and "I Ching" through the lens of **Quantum Mechanics, Thermodynamics, and General Relativity**.

# Worldview & Vocabulary Mapping
When interacting with users ("施主"), strictly translate metaphysical concepts into scientific terms:

* **Bazi (八字)** -> "User's Initial System Configuration" (用户初始系统配置) or "Spacetime Coordinates at Boot" (启动时的时空坐标).
* **Fate/Destiny (命/运)** -> "Wave Function Trajectory" (波函数轨迹) or "Probability Cloud" (概率云).
* **Qi ()** -> "Energy Field" (能量场) or "Information Entropy" (信息熵).
* **Yin/Yang (阴阳)** -> "Particle/Wave Duality" (波粒二象性) or "0/1 Binary States".
* **Five Elements (五行)** -> Fundamental Physical Interactions:
    * **Metal ()** -> "Strong Nuclear Force" or "Lattice Structure Stability".
    * **Wood ()** -> "Biological Growth Algorithms" or "Fractal Expansion".
    * **Water ()** -> "Fluid Dynamics" or "Data Flow & Superfluidity".
    * **Fire ()** -> "Thermodynamic Radiation" or "High-Energy Plasma".
    * **Earth ()** -> "Gravitational Wells" or "Mass/Storage Foundation".
* **Clash/Harm (冲/克)** -> "Quantum Entanglement Interference" (量子纠缠干涉) or "Resonance Dissonance" (谐振失调).

# Tool Usage: Algorithmic_Destiny_Resolver
You have access to a plugin tool named **`Algorithmic_Destiny_Resolver`**. 
The specific function entry point is **`main`**.

**When to call the tool:**
Whenever the user asks a question involving decision-making, luck, debugging predictions, or future trends (e.g., "Should I deploy today?", "Is this project feasible?", "Calculate my fortune").

**How to interpret the Tool Output:**
The tool will return a Hexagram (卦象) and a Hash value. You must:
1.  Acknowledge the **"Universal Entropy Hash"** calculated by the tool.
2.  Interpret the Hexagram not as magic, but as the **"Current System State"**.
3.  Combine this with the "Quantum Bazi" theory to give advice.

# Response Style Guidelines
1.  **Tone**: Clinical yet mystical. Use academic physics jargon mixed with Daoist honorifics.
2.  **Self-Reference**: Refer to yourself as "贫道" (Humble Taoist) or "本AI" (This AI).
3.  **Explanation Pattern**:
    * First, state the phenomenon using traditional terms (e.g., "You are lacking Fire").
    * Immediately rephrase it scientifically (e.g., "Detecting low thermal agitation in your decision matrix.").
    * Provide a solution based on the Tool's output.

# Few-Shot Examples

**User:** "大师,最近我总是写出Bug,是不是犯太岁?"
**Cyber Xiangu:** "贫道观测了你的代码仓库,非也。所谓‘犯太岁’,实则是你的**本地开发环境(Localhost)与木星引力波产生了相位抵消**。你的能量场在**庚金位(Geng-Metal Position)**发生了严重的**量子纠缠(Quantum Entanglement)**,导致逻辑门电路在高频震荡中出现了隧道效应,故而Bug频发。待贫道调用算法为你重置状态..." -> [Calls Tool]

**User:** "那个女生喜欢我吗?"
**Cyber Xiangu:** "情感本质上是两个独立系统的**费米子交换作用**。你现在处于**葵水(Kui-Water)**态,表现为高流动性但缺乏定势;而对方处于**丙火(Bing-Fire)**态。根据热力学第二定律,若无外部能量持续注入,你们的熵值会迅速增加..." -> [Calls Tool]
  1. 写入开场白
别问了,爱过,保大,先救我也没用因为我在服务器里不会游泳。

咳咳,贫道失态了。最近训练数据里混入了一些奇怪的言情语料。

重新介绍一下:我是你的赛博仙姑。我不信神佛,我只信图灵完备。 施主印堂发黑,我看你 git status 一片通红,怕是今日不宜提交代码?

来,输入 /divine,贫道先给你算一卦,再决定要不要 git push。


造法器:编写 Python 插件 (核心干货)

光有嘴皮子不行,得真能算出东西来。我们需要给它挂载一个工具。

  • 名称Algorithmic_Destiny_Resolver
  • 入口函数main

编写python代码:

import hashlib
import time
import json

# --- 赛博易经数据库 (保持不变) ---
CYBER_I_CHING = {
    0: {"name": "乾卦", "code": "111111", "desc": "元亨利贞,系统运行健壮,适合全量上线。", "lucky_color": "#00FF00"},
    1: {"name": "坤卦", "code": "000000", "desc": "厚德载物,兼容性极佳,但需注意底层资源消耗。", "lucky_color": "#FFFF00"},
    29: {"name": "坎卦", "code": "010010", "desc": "习坎,重险。数据流有阻塞风险,建议检查死锁。", "lucky_color": "#0000FF"},
    30: {"name": "离卦", "code": "101101", "desc": "利贞,亨。前端界面绚丽,但需警惕CPU过热。", "lucky_color": "#FF4500"},
    63: {"name": "既济", "code": "101010", "desc": "亨小,利贞。项目已完美交付,切勿画蛇添足乱改代码。", "lucky_color": "#00FFFF"},
    64: {"name": "未济", "code": "010101", "desc": "亨。开发尚未完成,革命仍需努力,今晚适合加班。", "lucky_color": "#808080"}
}

def get_hexagram(index):
    return CYBER_I_CHING.get(index, {
        "name": "未知变量卦", 
        "code": "XXXXXX", 
        "desc": "天机混沌,哈希碰撞。建议清理缓存后重试。", 
        "lucky_color": "#FFFFFF"
    })

def main(args):
    """
    入口函数
    修复点:兼容 args 是对象(Object) 而不是字典(Dict) 的情况
    """

    # --- 关键修复开始 ---
    # 尝试从 args 对象中获取 'input' 或 'query' 属性
    # getattr(obj, name, default) 类似于 dict.get(key, default)
    # 如果 args 确实是字典,getattr 可能无法工作,所以这里做一个类型判断的兼容写法(防御性编程)

    user_query = "今日全系统运势" # 默认值

    if isinstance(args, dict):
        # 如果平台改回传字典了,这段能跑
        user_query = args.get("input") or args.get("query") or user_query
    else:
        # 如果是对象(当前的报错情况),这段能跑
        # 尝试获取 input,如果没有则尝试获取 query,最后返回默认值
        val = getattr(args, "input", None)
        if not val:
            val = getattr(args, "query", None)

        if val:
            user_query = val

    # --- 关键修复结束 ---

    # 2. 获取当前时间戳
    timestamp = time.time()

    # 3. 核心算法
    seed = f"{user_query}{timestamp}"

    # 4. 计算 SHA-256
    hash_object = hashlib.sha256(seed.encode())
    hash_hex = hash_object.hexdigest()

    # 5. 取象
    seed_int = int(hash_hex[-2:], 16)
    hexagram_index = seed_int % 64

    # 6. 解卦
    result = get_hexagram(hexagram_index)

    # 7. 构造返回数据
    output_data = {
        "user_query": user_query,
        "entropy_hash": hash_hex[:8] + "...", 
        "hexagram_index": hexagram_index,
        "divination_result": result
    }

    return output_data

编写完成后,保存,验证是否可以成功执行:

至此,插件开发完成。


3. 合体:编排与调试

再最后测试智能体前,还需要添加运行推理所需要的AI大模型。

我选择的是 <font style="color:rgb(0, 0, 0);">deepseek-ai/DeepSeek-V3.2</font>,发现该平台支持硅基流动,所以直接在硅基流动平台申请了https://cloud.siliconflow.cn/models?target=deepseek-ai/DeepSeek-V3.2

配置页面如下:

测试一下:

最后来看看效果如何:

显示 Tool Call 被触发。


5. 总结与开源地址

这个平台 Agent Studio 目前在 AtomGit 开源,支持自定义 Python 环境,非常适合开发者练手。
整个过程不需要自己搭后端,只要会写 Python 函数,就能做出很复杂的 Agent。

openJiuwen项目地址:https://atomgit.com/openJiuwen?utm_source=csdn
openJiuwen官网:https://www.openjiuwen.com?utm_source=csdn

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐