栏目分类

热点资讯

妻子的淫情

你的位置:铜锣烧系列 > 妻子的淫情 >

1314酒色网 怎样构建我方的简便AI代理来排斥Kubernetes故障

发布日期:2025-06-29 12:01    点击次数:143

1314酒色网 怎样构建我方的简便AI代理来排斥Kubernetes故障

心电图 偷拍

AutoGen v0.4 发布!用 AgentChat 庸碌构建 Kubernetes 故障排斥助手 Kaia。愚弄 Ollama 免费 LLM (如 qwen2) 创建 AssistantAgent,麇集 kubectl 器用,构建单东说念主 RoundRobinGroupChat 团队。加入 UserProxyAgent 杀青东说念主工侵犯1314酒色网,界说罢手词,体验 AI 驱动的云原生运维!

译自:How to build your own simple AI agent to troubleshoot Kubernetes作家:Anton Weiss

终于来了!AI 助手不错匡助咱们与机器对话了。天然,它们也不错匡助咱们处理 Kubernetes。

底下先容怎样使用最近发布的 AutoGen v0.4 AgentChat 功能构建你我方的(天然尽头基础)Kubernetes 故障排斥助手。

AutoGen v0.4

AutoGen 是一个逾越的开源代理软件框架,刚刚通过 0.4 版块的发布进行了紧要检阅。新版块中的一项改动是加多了 AgentChat 层,这使得构建有用的助手变得愈加容易。以下是新的 AutoGen 0.4 分层架构图:

构建一个 Agent 团队

AgentChat 为咱们提供了用户友好的轮廓,不错匡助创建 AI agent 并将它们分组到团队中,以便它们不错共同朝着一个共同的主义竭力于。

创建一个 agent 尽头简便:

pythonagent = AssistantAgent(name="my_agent",llm_client=llm_client)

将 agent 放入团队中不错这么操作:

pythonteam = RoundRobinGroupChat([agent1,agent2],termination_condition=termination)stream = team.run_stream(task="Do something useful.")

使用 LLM

Agent 的基本使命格局是将任务发送到模子,并提供不错匡助完成任务的器用。LLM 掂量完成任务的正确器用敕令,agent 调用这些器用,将输出复返给 LLM,然后模子掂量任务的正确贬责决议。

因此,咱们需要将咱们的 agent 一语气到一个模子。咱们天然不错使用 OpenAI、Claude 或其他着名模子,但这频频意味着注册并最终付费。只是为了玩开源?!天然不是!相悖,咱们将使用带有开源、免费使用的模子的 Ollama。红运的是,当今不乏轻量级模子,即使莫得 GPU 也不错运行推理。在本示例中,我使用的是“qwen2”模子,但你不错使用你选拔的任何其他模子。是的,要是你不介怀推敲 Google 进行简便的 Kubernetes 故障排斥,你也不错免费使用 Gemini。AutoGen 救济悉数 主要的 LLM 提供商:

AgentChat 与 Ollama

通过运行 brew install ollama 安设 Ollama(要是你使用的是 Mac)1314酒色网,或者按照你选拔的 OS 的 官方安设理会 进行安设。

安设完成后,拉取模子:ollama pull qwen2然后通过运行以下敕令来提供做事:ollama serve

为了从咱们的代码中实例化一个模子,咱们将使用 OllamaChatCompletionClient 对象,并使用以下参数:

pythonmodel_client = OllamaChatCompletionClient(model="qwen2",keep_alive="60m", response_format=StructuredOutput)

创建 Agent

一朝咱们有了可用的模子,咱们就不错使用 AgentChat 的 AssistantAgent(内置 agent,它使用讲话模子并具有使用器用的材干)来创建咱们有用的助手。

pythonagent = AssistantAgent( name="kaia", model_client=model_client, tools=[tool], system_message="""You are a Kubernetes troubleshooting agent. When asked about a resource but no namespace is specified - you can run kubectl get resource_type -A and then analyze the output to find the resource name. That's how you find the namespace where a resource is located. If the resource is a pod - you MUST inspect the pod's logs for issues. The correct command to do that is: kubectl logs <pod_name> -n <namespace>. If a resource is not found in any namespace, inform me that it was not found.""", reflect_on_tool_use=True, )

在这里,我创建了一个名为 kaia (Kubernetes** AI A**gent) 的 agent,它使用我之前创建的基于 Ollama 的 LLM 客户端,并汲取到一个尽头详备的系统请示,理会注解了应该怎样排斥 Kubernetes pod 的故障。(我花了约莫 20 次迭代才念念出一个请示,不错最大规则地减少幻觉)。我还告诉它 reflect_on_tool_use,这会导致它使用器用调用和收尾进行另一次模子推理,以生成反馈。

我念念修改其他 agent 参数不错产生更好的收尾,但对于本示例,我坚抓使用基本学问。

提供器用

正如照旧筹商过的,agent 需要器用来完成其使命。在这个简便的例子中,我只是让它打听我的 kubectl。对于更高档的用例,皆备要望望往常几个月创建的广阔 Kubernetes MCP 做事器之一。这是 Alexey Ledenev 创建的此类做事器的一个例子:https://github.com/alexei-led/k8s-mcp-server。

但在这里,我只是界说一个调用 kubectl 的函数并将其包装在 AutoGen FunctionTool 中:

pythondef call_kubectl(command: str) -> str: """Call any kubectl command in the current cluster context""" if command == '': return subprocess.check_output(['kubectl', '']) if command.split()[0] != 'kubectl': command = 'kubectl ' + command return (subprocess.check_output(command.split()))tool = FunctionTool(call_kubectl, description="Kubernetes Command Execution", strict=True)

单东说念主团队

当今互联网上有许多对于在 GenAI 的匡助下,一个东说念主怎样取代悉数这个词团队的筹商。不细目这对东说念主类来说是否果真,毕竟咱们组建团队不单是是为了提升坐蓐力。

但对于 AI agent 来说,这皆备可行。(即使也有这么一种意见,即高度专科化的 AI agent 比处理悉数使命的通用 agent 寄托更好的收尾)。非论怎样,对于 Kaia 来说,单 agent 团队照旧富余了,Kaia 的独一主义是对 Kubernetes 进行故障排斥。在 AgentChat 中创建这么一个单东说念主团队的最简便姿首是使用 RoundRobinGroupChat - 一种简便而有用的团队建树,其中悉数 agent 分享疏导的高下文,并以轮回格局轮替反馈。

在轮回中添加东说念主工

天然,咱们都设念念一个翌日,机器不仅会发现问题,还会无需商讨咱们即可竖立它们。但是,当今 AI 容易产生幻觉,因此咱们尽头但愿审查它决定作念的任何事情。在 agent 团队中添加东说念主工审查员的姿首是创建一个 UserProxyAgent:

pythonuser_proxy = UserProxyAgent("user_proxy", input_func=input)

罢手词

咱们的 agent 将继续使命,直到任务完成。但什么时分才算完成?AgentChat 团队允许咱们界说断绝要求,允许 agent 相互陈述何时罢手聊天和调用器用。在 Kaia 的例子中,我合计在团队和洽中保抓感德和礼貌老是好的,是以我的断绝音讯是“Thanks!”。还有其他可能的格局来断绝 agent 群聊:TerminationCondition。请良好,咱们还不错界说 max_turns 参数来截止 agent 交互的总次数。

是以终末,让咱们创建咱们的团队:

pythontermination_condition = TextMentionTermination("Thanks!")team = RoundRobinGroupChat( [agent, user_proxy], termination_condition=termination_condition, # max_turns=10)

让咱们驱动使命!

咱们当今需要作念的便是取得用户的输入,即 Kubernetes 故障排斥的恳求,并运行团队直到找到谜底:

pythonasync def ainput(string: str) -> str: await asyncio.to_thread(sys.stdout.write, f'{string}') return await asyncio.to_thread(sys.stdin.readline)async def main(): print("What do you want to know?"); prompt = await ainput("Prompt:\n") # Ignoring warnings to clean up the output. with warnings.catch_warnings(): warnings.simplefilter("ignore") async for message in team.run_stream(task=prompt): # type: ignore if type(message).__name__ == "TextMessage" or type(message).__name__ == "UserInputRequestedEvent": if message.source not in ["user_proxy", "user"]: print(message.content) print("Type 'Thanks!' if you're done.\n")asyncio.run(main())

请良好,我正在进行一些音讯清算,以防患 AgentChat 向规则台打印太多内容。

使用 AI 对 Kubernetes 进行故障排斥

要运行我编写的代码,请本质以下操作:

bashgit clone https://github.com/otomato-gh/kaiacd kaiapip install -r requirements.txtpython3 kaia.py

然后使用近似以下内容请示它:“pod dummy 有什么问题?”

不雅看以下视频以了解 kaia 的实质应用。然后单击此处取得此简便基本 AI agent 的好意思满代码。然后在您我方的环境中运行它,让我知说念收尾怎样。您念念添加什么?它产生几许幻觉?哪个 LLM 对您来说成果最佳?接下来是什么?我将把Kaia一语气到语音识别,最终大约真确地对我的集群低语。太欢乐了!

期待您的回信1314酒色网。



Powered by 铜锣烧系列 @2013-2022 RSS地图 HTML地图

Copyright Powered by站群系统 © 2013-2024