快速上手
用 Python 跑一个智能体,或启动 Near 连接的本机 Studio。
快速上手
两条都成立的第一次运行,选一条。它们不是同一套循环。
| 路径 | 入口 | 循环 |
|---|---|---|
| SDK | Agent + Task + AgentExecutor | agenticx/core/agent_executor.py 里的经典任务执行器 |
| Studio / Near | agx serve 再开桌面 | agenticx/runtime/agent_runtime.py 的 AgentRuntime.run_turn |
路径 A — 嵌进 Python
python
1from agenticx import Agent, Task, AgentExecutor2from agenticx.llms import OpenAIProvider3from agenticx.tools.function_tool import tool45@tool(name="add", description="Add two integers.")6def add(a: int, b: int) -> int:7 return a + b89agent = Agent(10 name="Analyst",11 role="Data analysis helper",12 goal="Answer numeric questions",13 organization_id="my-org",14)15task = Task(16 id="sum-1",17 description="What is 42 + 58?",18 expected_output="The integer sum",19)2021executor = AgentExecutor(22 llm_provider=OpenAIProvider(model="gpt-4o"),23 tools=[add],24)25result = executor.run(agent=agent, task=task)26print(result)
路径 B — 给 Near 用的本机 Studio
bash
1agx serve --host 127.0.0.1 --port 8000
桌面端通常会自己在 127.0.0.1 上拉起,端口随机,并写入 ~/.agenticx/serve.port 与 ~/.agenticx/serve.token。若你自己起服务,Near 必须指到这个地址。
agx studio 是终端 REPL,不是 FastAPI 进程。见 Studio 服务。
路径 C — 一次性 CLI
bash
1agx run "用两句话说明 AgenticX 是什么"
适合在开桌面之前先确认供应商配置能通。
如果没反应
agx --version失败 → 当前PATH里没有这个包- 供应商 401 → 密钥没配或环境变量不对
- 桌面分身 / 历史全空 →
agx serve没在听(看~/.agenticx/serve.port) - 工具循环过早停 → 在 配置 里调大
runtime.max_tool_rounds/AGX_MAX_TOOL_ROUNDS