Skip to main content

langfuse-pydantic-ai

Project description

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.

⚠️ This package is experimental and not fully tested. Use at your own risk.

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.data)


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)

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langfuse_pydantic_ai-0.0.2.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langfuse_pydantic_ai-0.0.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file langfuse_pydantic_ai-0.0.2.tar.gz.

File metadata

  • Download URL: langfuse_pydantic_ai-0.0.2.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for langfuse_pydantic_ai-0.0.2.tar.gz
Algorithm Hash digest
SHA256 1017baa3cf7e0524f53454568a5b20345db0259c61a35fa9e3ed18a82faf57e4
MD5 4ccef3c6ac97b39157acdac125ab65e1
BLAKE2b-256 7a6e07e7c61afc5bb69218c72f0b4338d36d87937af40c4093ad4f238e6fdea1

See more details on using hashes here.

File details

Details for the file langfuse_pydantic_ai-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for langfuse_pydantic_ai-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 607802f2bfc7b414e9084ad90bf54c641112da1b464f33908f2eb0a1a4e6898c
MD5 1007b706135c8fe861c0f4278b64c24e
BLAKE2b-256 c6245251be49a45e6cbfdd31ad4879267a8518335e94b740601ea9148e17742f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page