Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ Langtrace automatically captures traces from the following vendors:
| Autogen | ❌ | ✅ |
| HiveAgent | ❌ | ✅ |
| Inspect AI | ❌ | ✅ |
| Graphlit | ❌ | ✅ |
| Phidata | ❌ | ✅ |
| Arch | ❌ | ✅ |

### Vector Databases
| Database | TypeScript SDK | Python SDK |
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dev = [
"google-cloud-aiplatform",
"mistralai",
"embedchain",
"phidata",
]

test = ["pytest", "pytest-vcr", "pytest-asyncio"]
Expand Down
9 changes: 9 additions & 0 deletions src/examples/phidata_example/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import asyncio
from examples.phidata_example.agent import agent_run
from langtrace_python_sdk import langtrace

langtrace.init()

class PhiDataRunner:
def run(self):
agent_run()
16 changes: 16 additions & 0 deletions src/examples/phidata_example/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from langtrace_python_sdk import langtrace
from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.duckduckgo import DuckDuckGo

langtrace.init()

def agent_run():
web_agent = Agent(
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGo()],
instructions=["Always include sources"],
show_tool_calls=True,
markdown=True,
)
web_agent.print_response("how do I get from lagos to nairobi, through kigali rwanda (staying a week) and how much would it cost on average?", stream=True)
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"CEREBRAS": "Cerebras",
"MILVUS": "Milvus",
"GRAPHLIT": "Graphlit",
"PHIDATA": "Phidata",
}

LANGTRACE_ADDITIONAL_SPAN_ATTRIBUTES_KEY = "langtrace_additional_attributes"
2 changes: 2 additions & 0 deletions src/langtrace_python_sdk/instrumentation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .milvus import MilvusInstrumentation
from .google_genai import GoogleGenaiInstrumentation
from .graphlit import GraphlitInstrumentation
from .phidata import PhiDataInstrumentation

__all__ = [
"AnthropicInstrumentation",
Expand Down Expand Up @@ -61,4 +62,5 @@
"GoogleGenaiInstrumentation",
"CrewaiToolsInstrumentation",
"GraphlitInstrumentation",
"PhiDataInstrumentation",
]
5 changes: 5 additions & 0 deletions src/langtrace_python_sdk/instrumentation/phidata/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .instrumentation import PhiDataInstrumentation

__all__ = [
"PhiDataInstrumentation",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""
Copyright (c) 2024 Scale3 Labs

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.trace import get_tracer
from wrapt import wrap_function_wrapper as _W
from typing import Collection
from importlib_metadata import version as v
from .patch import patch_agent, patch_memory

class PhiDataInstrumentation(BaseInstrumentor):
def instrumentation_dependencies(self) -> Collection[str]:
return ["phidata >= 2.7.10"] # Adjust version as needed

def _instrument(self, **kwargs):
tracer_provider = kwargs.get("tracer_provider")
tracer = get_tracer(__name__, "", tracer_provider)
version = v("phidata")

try:
_W(
"phi.agent.agent",
"Agent.run",
patch_agent("Agent.run", version, tracer),
)
_W(
"phi.agent.agent",
"Agent.arun",
patch_agent("Agent.arun", version, tracer),
)
_W(
"phi.agent.agent",
"Agent._run",
patch_agent("Agent._run", version, tracer),
)
_W(
"phi.agent.agent",
"Agent._arun",
patch_agent("Agent._arun", version, tracer),
)

_W(
"phi.memory.agent",
"AgentMemory.update_memory",
patch_memory("AgentMemory.update_memory", version, tracer),
)
_W(
"phi.memory.agent",
"AgentMemory.aupdate_memory",
patch_memory("AgentMemory.aupdate_memory", version, tracer),
)
_W(
"phi.memory.agent",
"AgentMemory.update_summary",
patch_memory("AgentMemory.update_summary", version, tracer),
)
_W(
"phi.memory.agent",
"AgentMemory.aupdate_summary",
patch_memory("AgentMemory.aupdate_summary", version, tracer),
)

except Exception:
pass

def _uninstrument(self, **kwargs):
pass
Loading