langfuse_pydantic_ai
This is a third-party package, not officially maintained by Langfuse. If Langfuse requires for this package, feel free to contact me.
A simple wrapper, send trace to langfuse when using pydantic-ai
Install
pip install langfuse-pydantic-ai
Usage
TL;DR
from langfuse_pydantic_ai import observed_agent
agent = observed_agent(agent)
Full example:
import asyncio
from pydantic_ai.agent import Agent
from langfuse.decorators import observe
from langfuse_pydantic_ai import observed_agent
@observe # Add this decorator to span a trace
async def main():
agent = Agent(
"google-gla:gemini-1.5-flash",
# Register a static system prompt using a keyword argument to the agent.
# For more complex dynamically-generated system prompts, see the example below.
system_prompt="Be concise, reply with one sentence.",
)
agent = observed_agent(agent)
result = await agent.run('Where does "hello world" come from?')
print(result.output)
if __name__ == "__main__":
asyncio.run(main())
If using custom model, use observed_model instead
from pydantic_ai.agent import Agent
from langfuse_pydantic_ai import observed_model
model = observed_model(model)
agent = Agent(model=model)
If using agent factory function, use @use_observed_agent directly
from pydantic_ai.agent import Agent
from langfuse_pydantic_ai import use_observed_agent
@use_observed_agent
def init_agent() -> Agent:
return Agent(
"google-gla:gemini-1.5-flash",
# Register a static system prompt using a keyword argument to the agent.
# For more complex dynamically-generated system prompts, see the example below.
system_prompt="Be concise, reply with one sentence.",
)
Configuration via environment variables:
LANGFUSE_HOST=<langfuse_host>
LANGFUSE_PUBLIC_KEY=<langfuse_public_key>
LANGFUSE_SECRET_KEY=<langfuse_secret_key>
Develop
Install pre-commit before commit
pip install pre-commit
pre-commit install
Install package locally
pip install -e .[test]
Run unit-test before PR
pytest -v
Metadata
Release files for langfuse-pydantic-ai 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| langfuse_pydantic_ai-0.2.1.tar.gz | 14.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langfuse_pydantic_ai-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.0 kB
Release files / langfuse_pydantic_ai-0.2.1.tar.gz
| Download URL | langfuse_pydantic_ai-0.2.1.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba7374a42f5864a0d3f893793af8842836db16d7db3fbe5f412aac284f9c27fe
|
|
BLAKE2b-256 checksum How to use checksums |
1f9e8d530251d719dc69715001a9bda966b5476909fc5abaa05c76e8c3c94f85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / langfuse_pydantic_ai-0.2.1-py3-none-any.whl
| Download URL | langfuse_pydantic_ai-0.2.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80d7a3ccc8f99405a4f979332700d4163b124540c0f557b55f7dc65ee466cc09
|
|
BLAKE2b-256 checksum How to use checksums |
91850082faeb5292e6dadb52b530989b87bd28831abc6eca0b42991dcfd30236
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for langfuse-pydantic-ai 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.