ARTICLE DETAIL

资讯详情

深耕编程入门与网站建设的一线实战洞察。

first_message.md

first_message.md first_message.md【免费下载链接】gpt-computer-assistantBuild autonomous AI agents in Python.项目地址: https://gitcode.com/GitHub_Trending/gp/gpt-computer-assistantNew experiment.Experiment name:{research_name}Research source:{research_source}Current notebook:{current_notebook}占位符校验与渲染的实现位于 [prebuilt_agent_base.py](https://link.gitcode.com/i/d3f0ec437688248b497c28d935052d4c)_extract_template_fields 用 string.Formatter().parse 解析模板并支持 field.attr 与 field[index] 形式_render_first_message 会列出**全部**缺失占位符并抛出带提示的 ValueError。真实案例可对照 [applied_scientist 的 first_message.md](https://link.gitcode.com/i/e4982ee8dc1eb0400c5d6583444850c2)——它使用了 {research_name}、{research_source}、{current_notebook}、{current_data}、{experiments_directory} 五个占位符。 ### 4.3 skills/skill_name/SKILL.md —— 按需加载的技能文件 Anthropic 风格的技能文件每个都是 Agent 按需加载的、自包含的、有边界的单项能力。基类会把整个 skills/ 树**原样复制**进工作区因此系统提示词中凡是引用相对路径的东西都能被找到。参考实现见 [experiment_management/SKILL.md](https://link.gitcode.com/i/018e5965c9c4b91b13b5a0641b86cb18)Phase 0 实验管理与 [evaluate/SKILL.md](https://link.gitcode.com/i/40d4bd8caf73ff221a86111e1b9c9a13)Phase 5 评估与 result.json 产出。 ## 5. 步骤三在 agent.py 中继承基类 python # src/upsonic/prebuilt/your_agent/agent.py from __future__ import annotations from typing import Any, Optional, Union, TYPE_CHECKING from upsonic.prebuilt.prebuilt_agent_base import PrebuiltAutonomousAgentBase if TYPE_CHECKING: from upsonic.models import Model class YourAgent(PrebuiltAutonomousAgentBase): Short docstring describing the agent and its high-level API. AGENT_REPO: str https://github.com/Upsonic/Upsonic AGENT_FOLDER: str src/upsonic/prebuilt/your_agent/template def __init__( self, *, model: Union[str, Model] openai/gpt-4o, workspace: Optional[str] None, **kwargs: Any, ) - None: # The base class accepts agent_repo/agent_folder; pin them here so # users only have to think about model workspace. kwargs.pop(agent_repo, None) kwargs.pop(agent_folder, None) super().__init__( modelmodel, workspaceworkspace, agent_repoself.AGENT_REPO, agent_folderself.AGENT_FOLDER, **kwargs, )这段代码本身已经足够——用户现在就可以调用agent.run(workspace./ws, **template_params)。要点拆解AGENT_REPO/AGENT_FOLDER是类常量子类在__init__中先把用户可能误传的agent_repo/agent_folder从kwargs弹出kwargs.pop再以类常量把它们钉死在super().__init__上。这样用户只需关心model与workspace。TYPE_CHECKING下的Model导入仅用于类型标注避免运行时循环导入。workspace语义可在构造时传入也可在每次run()时传入两处都省略则会在运行时抛出ValueError见_bootstrap中对autonomous_workspace is None的检查。基类构造签名PrebuiltAutonomousAgentBase.__init__额外接收agent_repo与agent_folder两个关键字参数并将它们连同首次运行前的模板缓存字段一并初始化见 prebuilt_agent_base.py。6. 步骤四可选提供模板感知的高层 API用户不应该被迫记住first_message.md里的占位符名字。把它们封装进一个有类型的工厂方法并可选地返回一个“延迟真正运行”的小对象def new_task(self, name: str, *, source: str, target: str) - YourTask: return YourTask( agentself, template_params{name: name, source: source, target: target}, )如果你的 Agent 需要以下能力请以applied_scientist中的Experiment对象为参考前台 vs 后台运行run()pretty TTY 输出与run_in_background()静默、Jupyter 友好。对 Jupyter 友好的实时进度轮询Experiment.progress_bar从磁盘上的progress.json渲染 HTML 进度条AppliedScientist.progress_bar_live()可阻塞当前 cell 并定时刷新。磁盘上的运行记录/注册表ExperimentRegistry提供对experiments.json的 dict-like 实时视图ExperimentResult结构化暴露verdict/summary/explanation/table等字段。applied_scientist之所以暴露一个类而不是薄函数正是为了让 Notebook 调用方能持有一个运行中实验的句柄、观察其进度条、稍后检查结果——只有当你需要这种能力时才复制这个模式。参考实现要点applied_scientist/agent.pynew_experiment(name, *, research_source, current_notebook, current_dataNone, experiments_directoryNone, inputsNone)只“准备”不“运行”current_data缺省时模板会收到占位符文本(not provided — infer it from the current notebooks>from __future__ import annotations from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from .agent import YourAgent # plus any helper classes def _get_classes() - dict[str, Any]: from .agent import YourAgent return {YourAgent: YourAgent} def __getattr__(name: str) - Any: classes _get_classes() if name in classes: return classes[name] raise AttributeError( fmodule {__name__} has no attribute {name}. fAvailable: {list(classes.keys())} ) __all__ [YourAgent]包级src/upsonic/prebuilt/__init__.py—— 把 Agent 加入包级_get_classes()与__all__使from upsonic.prebuilt import YourAgent生效def _get_classes() - dict[str, Any]: from .prebuilt_agent_base import PrebuiltAutonomousAgentBase from .applied_scientist.agent import AppliedScientist, Experiment, ExperimentResult from .your_agent.agent import YourAgent # ← new return { PrebuiltAutonomousAgentBase: PrebuiltAutonomousAgentBase, AppliedScientist: AppliedScientist, Experiment: Experiment, ExperimentResult: ExperimentResult, YourAgent: YourAgent, # ← new } __all__ [ PrebuiltAutonomousAgentBase, AppliedScientist, Experiment, ExperimentResult, YourAgent, # ← new ]懒加载_get_classes()内部才import能让import upsonic保持轻量——不要把这些导入移到文件顶部的无条件导入。可对照仓库现状prebuilt/init.py 与 applied_scientist/init.py 的实现。8. 测试你的 Prebuilt一个最小冒烟测试from upsonic.prebuilt import YourAgent agent YourAgent(modelopenai/gpt-4o, workspace./ws) # Verify constants and inheritance assert agent.AGENT_FOLDER src/upsonic/prebuilt/your_agent/template assert agent.AGENT_REPO.endswith(/Upsonic) # Run end-to-end (cheap model recommended for CI) agent.run(source..., target...)针对尚未合并的模板进行本地开发时覆写仓库地址即可agent YourAgent( modelopenai/gpt-4o, workspace./ws, agent_repohttps://github.com/your_fork/Upsonic, )【免费下载链接】gpt-computer-assistantBuild autonomous AI agents in Python.项目地址: https://gitcode.com/GitHub_Trending/gp/gpt-computer-assistant创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表