CrewAI智能体开发:Arize Phoenix
Arize Phoenix - CrewAI 集成支持 OpenTelemetry 和 OpenInferenceArize Phoenix 集成本指南演示了如何通过 OpenInference SDK 使用 OpenTelemetry 将Arize Phoenix与CrewAI集成。完成本指南后您将能够追踪您的 CrewAI 代理并轻松调试您的代理。什么是 Arize PhoenixArize Phoenix 是一个 LLM 可观测性平台为 AI 应用程序提供追踪和评估。开始使用我们将通过一个简单的示例来演示如何使用 CrewAI 并通过 OpenInference 使用 OpenTelemetry 将其与 Arize Phoenix 集成。您也可以在 Google Colab 上查阅本指南。步骤 1安装依赖项pip install openinference-instrumentation-crewai crewai crewai-tools arize-phoenix-otel步骤 2设置环境变量设置 Phoenix Cloud API 密钥并配置 OpenTelemetry 以将追踪发送到 Phoenix。Phoenix Cloud 是 Arize Phoenix 的托管版本但使用此集成并非必需。您可以在此处获取免费的 Serper API 密钥。import os from getpass import getpass # Get your Phoenix Cloud credentials PHOENIX_API_KEY getpass( Enter your Phoenix Cloud API Key: ) # Get API keys for services OPENAI_API_KEY getpass( Enter your OpenAI API key: ) SERPER_API_KEY getpass( Enter your Serper API key: ) # Set environment variables os.environ[PHOENIX_CLIENT_HEADERS] fapi_key{PHOENIX_API_KEY} os.environ[PHOENIX_COLLECTOR_ENDPOINT] https://app.phoenix.arize.com # Phoenix Cloud, change this to your own endpoint if you are using a self-hosted instance os.environ[OPENAI_API_KEY] OPENAI_API_KEY os.environ[SERPER_API_KEY] SERPER_API_KEY步骤 3使用 Phoenix 初始化 OpenTelemetry初始化 OpenInference OpenTelemetry 检测 SDK以开始捕获追踪并将其发送到 Phoenix。from phoenix.otel import register tracer_provider register( project_namecrewai-tracing-demo, auto_instrumentTrue, )步骤 4创建 CrewAI 应用程序我们将创建一个 CrewAI 应用程序其中两个代理协同合作研究并撰写一篇关于人工智能进步的博客文章。from crewai import Agent, Crew, Process, Task from crewai_tools import SerperDevTool from openinference.instrumentation.crewai import CrewAIInstrumentor from phoenix.otel import register # setup monitoring for your crew tracer_provider register( endpointhttps://:6006/v1/traces) CrewAIInstrumentor().instrument(skip_dep_checkTrue, tracer_providertracer_provider) search_tool SerperDevTool() # Define your agents with roles and goals researcher Agent( roleSenior Research Analyst, goalUncover cutting-edge developments in AI and data science, backstoryYou work at a leading tech think tank. Your expertise lies in identifying emerging trends. You have a knack for dissecting complex data and presenting actionable insights., verboseTrue, allow_delegationFalse, # You can pass an optional llm attribute specifying what model you wanna use. # llmChatOpenAI(model_namegpt-3.5, temperature0.7), tools[search_tool], ) writer Agent( roleTech Content Strategist, goalCraft compelling content on tech advancements, backstoryYou are a renowned Content Strategist, known for your insightful and engaging articles. You transform complex concepts into compelling narratives., verboseTrue, allow_delegationTrue, ) # Create tasks for your agents task1 Task( descriptionConduct a comprehensive analysis of the latest advancements in AI in 2024. Identify key trends, breakthrough technologies, and potential industry impacts., expected_outputFull analysis report in bullet points, agentresearcher, ) task2 Task( descriptionUsing the insights provided, develop an engaging blog post that highlights the most significant AI advancements. Your post should be informative yet accessible, catering to a tech-savvy audience. Make it sound cool, avoid complex words so it doesnt sound like AI., expected_outputFull blog post of at least 4 paragraphs, agentwriter, ) # Instantiate your crew with a sequential process crew Crew( agents[researcher, writer], tasks[task1, task2], verbose1, processProcess.sequential ) # Get your crew to work! result crew.kickoff() print(######################) print(result)步骤 5在 Phoenix 中查看追踪运行代理后您可以在 Phoenix 中查看 CrewAI 应用程序生成的追踪。您将看到代理交互和 LLM 调用的详细步骤这有助于您调试和优化您的 AI 代理。登录您的 Phoenix Cloud 账户并导航到您在project_name参数中指定的项目。您将看到您的追踪的时间线视图其中包含所有代理交互、工具使用和 LLM 调用。版本兼容性信息Python 3.8CrewAI 0.86.0Arize Phoenix 7.0.1OpenTelemetry SDK 1.31.0参考资料Phoenix 文档 - Phoenix 平台概述。CrewAI 文档 - CrewAI 框架概述。OpenTelemetry 文档 - OpenTelemetry 指南OpenInference GitHub - OpenInference SDK 源代码。《AI提示工程必知必会》为读者提供了丰富的AI提示工程知识与实战技能。《AI提示工程必知必会》主要内容包括各类提示词的应用如问答式、指令式、状态类、建议式、安全类和感谢类提示词以及如何通过实战演练掌握提示词的使用技巧使用提示词进行文本摘要、改写重述、语法纠错、机器翻译等语言处理任务以及在数据挖掘、程序开发等领域的应用AI在绘画创作上的应用百度文心一言和阿里通义大模型这两大智能平台的特性与功能以及市场调研中提示词的实战应用。通过阅读《AI提示工程必知必会》读者可掌握如何有效利用AI提示工程提升工作效率创新工作流程并在职场中脱颖而出。