-
Notifications
You must be signed in to change notification settings - Fork 172
feat(beeai): Added tools support in beeai instrumentation #2543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
satyadevai
wants to merge
10
commits into
Arize-ai:main
Choose a base branch
from
satyadevai:2140-beeai-tools-issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
597ab83
Beeai Tools Issues
satyadevai 4132bcd
fix(beeai): tool calls fix
satyadevai 0746fd7
Merge branch 'main' into 2140-beeai-tools-issue
satyadevai bbce804
Initial test setup
satyadevai a52008f
Unit Test Cases added
satyadevai 25cb754
pydentic version for 3.14
satyadevai 1dd8edf
Reverting beeai pydentic version
satyadevai 4d98372
pydentic3.14 fix
satyadevai 6e51576
Fixing CI Issues
satyadevai 8bc8bc6
Cursor comments resolved
satyadevai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
python/instrumentation/openinference-instrumentation-beeai/examples/beeai_ax.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import asyncio | ||
| import os | ||
|
|
||
| from arize.otel import register | ||
| from beeai_framework.adapters.openai import OpenAIChatModel | ||
| from beeai_framework.agents.experimental import RequirementAgent | ||
| from beeai_framework.agents.experimental.requirements.conditional import ( | ||
| ConditionalRequirement, | ||
| ) | ||
| from beeai_framework.errors import FrameworkError | ||
| from beeai_framework.middleware.trajectory import GlobalTrajectoryMiddleware | ||
| from beeai_framework.tools import Tool | ||
| from beeai_framework.tools.handoff import HandoffTool | ||
| from beeai_framework.tools.search.wikipedia import WikipediaTool | ||
| from beeai_framework.tools.think import ThinkTool | ||
| from beeai_framework.tools.weather import OpenMeteoTool | ||
| from dotenv import load_dotenv | ||
|
|
||
| from openinference.instrumentation.beeai import BeeAIInstrumentor | ||
|
|
||
| load_dotenv() | ||
|
|
||
| arize_space_id = os.getenv("ARIZE_SPACE_ID") | ||
| arize_api_key = os.getenv("ARIZE_API_KEY") | ||
| openai_api_key = os.getenv("OPENAI_API_KEY") | ||
|
|
||
| tracer_provider = register( | ||
| space_id=arize_space_id, | ||
| api_key=arize_api_key, | ||
| project_name="beeai-cookbook", | ||
| ) | ||
|
|
||
| BeeAIInstrumentor().instrument(tracer_provider=tracer_provider) | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| knowledge_agent = RequirementAgent( | ||
| llm=OpenAIChatModel(model="gpt-4o-mini"), | ||
| # llm=ChatModel.from_name("ollama:granite3.3:8b"), | ||
| tools=[ThinkTool(), WikipediaTool()], | ||
| requirements=[ConditionalRequirement(ThinkTool, force_at_step=1)], | ||
| role="Knowledge Specialist", | ||
| instructions="Provide answers to general questions about the world.", | ||
| ) | ||
|
|
||
| weather_agent = RequirementAgent( | ||
| llm=OpenAIChatModel(model="gpt-4o-mini"), | ||
| tools=[OpenMeteoTool()], | ||
| role="Weather Specialist", | ||
| instructions="Provide weather forecast for a given destination.", | ||
| ) | ||
|
|
||
| main_agent = RequirementAgent( | ||
| name="MainAgent", | ||
| llm=OpenAIChatModel(model="gpt-4o-mini"), | ||
| # llm=ChatModel.from_name("ollama:granite3.3:8b"), | ||
| tools=[ | ||
| ThinkTool(), | ||
| HandoffTool( | ||
| knowledge_agent, | ||
| name="KnowledgeLookup", | ||
| description="Consult the Knowledge Agent for general questions.", | ||
| ), | ||
| HandoffTool( | ||
| weather_agent, | ||
| name="WeatherLookup", | ||
| description="Consult the Weather Agent for forecasts.", | ||
| ), | ||
| ], | ||
| requirements=[ConditionalRequirement(ThinkTool, force_at_step=1)], | ||
| # Log all tool calls to the console for easier debugging | ||
| middlewares=[GlobalTrajectoryMiddleware(included=[Tool])], | ||
| ) | ||
|
|
||
| question = ( | ||
| "If I travel to Rome next weekend, what should I expect in terms of weather, " | ||
| "and also tell me one famous historical landmark there?" | ||
| ) | ||
| print(f"User: {question}") | ||
|
|
||
| try: | ||
| response = await main_agent.run(question, expected_output="Helpful and clear response.") | ||
| print("Agent:", response) | ||
| except FrameworkError as err: | ||
| print("Error:", err.explain()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
85 changes: 85 additions & 0 deletions
85
python/instrumentation/openinference-instrumentation-beeai/examples/beeai_phoenix.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import asyncio | ||
|
|
||
| from beeai_framework.adapters.openai import OpenAIChatModel | ||
| from beeai_framework.agents.experimental import RequirementAgent | ||
| from beeai_framework.agents.experimental.requirements.conditional import ( | ||
| ConditionalRequirement, | ||
| ) | ||
| from beeai_framework.errors import FrameworkError | ||
| from beeai_framework.middleware.trajectory import GlobalTrajectoryMiddleware | ||
| from beeai_framework.tools import Tool | ||
| from beeai_framework.tools.handoff import HandoffTool | ||
| from beeai_framework.tools.search.wikipedia import WikipediaTool | ||
| from beeai_framework.tools.think import ThinkTool | ||
| from beeai_framework.tools.weather import OpenMeteoTool | ||
| from dotenv import load_dotenv | ||
| from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | ||
| from opentelemetry.sdk import trace as trace_sdk | ||
| from opentelemetry.sdk.trace.export import SimpleSpanProcessor | ||
|
|
||
| from openinference.instrumentation.beeai import BeeAIInstrumentor | ||
|
|
||
| load_dotenv() | ||
|
|
||
| endpoint = "http://localhost:6006/v1/traces" | ||
|
|
||
| tracer_provider = trace_sdk.TracerProvider() | ||
| tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint))) | ||
|
|
||
| BeeAIInstrumentor().instrument(tracer_provider=tracer_provider) | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| knowledge_agent = RequirementAgent( | ||
| llm=OpenAIChatModel(model="gpt-4o-mini"), | ||
| # llm=ChatModel.from_name("ollama:granite3.3:8b"), | ||
| tools=[ThinkTool(), WikipediaTool()], | ||
| requirements=[ConditionalRequirement(ThinkTool, force_at_step=1)], | ||
| role="Knowledge Specialist", | ||
| instructions="Provide answers to general questions about the world.", | ||
| ) | ||
|
|
||
| weather_agent = RequirementAgent( | ||
| llm=OpenAIChatModel(model="gpt-4o-mini"), | ||
| tools=[OpenMeteoTool()], | ||
| role="Weather Specialist", | ||
| instructions="Provide weather forecast for a given destination.", | ||
| ) | ||
|
|
||
| main_agent = RequirementAgent( | ||
| name="MainAgent", | ||
| llm=OpenAIChatModel(model="gpt-4o-mini"), | ||
| # llm=ChatModel.from_name("ollama:granite3.3:8b"), | ||
| tools=[ | ||
| ThinkTool(), | ||
| HandoffTool( | ||
| knowledge_agent, | ||
| name="KnowledgeLookup", | ||
| description="Consult the Knowledge Agent for general questions.", | ||
| ), | ||
| HandoffTool( | ||
| weather_agent, | ||
| name="WeatherLookup", | ||
| description="Consult the Weather Agent for forecasts.", | ||
| ), | ||
| ], | ||
| requirements=[ConditionalRequirement(ThinkTool, force_at_step=1)], | ||
| # Log all tool calls to the console for easier debugging | ||
| middlewares=[GlobalTrajectoryMiddleware(included=[Tool])], | ||
| ) | ||
|
|
||
| question = ( | ||
| "If I travel to Rome next weekend, what should I expect in terms of weather, " | ||
| "and also tell me one famous historical landmark there?" | ||
| ) | ||
| print(f"User: {question}") | ||
|
|
||
| try: | ||
| response = await main_agent.run(question, expected_output="Helpful and clear response.") | ||
| print("Agent:", response) | ||
| except FrameworkError as err: | ||
| print("Error:", err.explain()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.