Skip to content

feat(mappers): langfuse provider changes to support newer version of langfuse#165

Open
poshinchen wants to merge 2 commits intostrands-agents:mainfrom
poshinchen:feat/mappers-langfuse-change
Open

feat(mappers): langfuse provider changes to support newer version of langfuse#165
poshinchen wants to merge 2 commits intostrands-agents:mainfrom
poshinchen:feat/mappers-langfuse-change

Conversation

@poshinchen
Copy link
Contributor

@poshinchen poshinchen commented Mar 16, 2026

Description

LangfuseProvider multi-framework support

  • Makes LangfuseProvider work with traces from any framework (LangChain, Strands, LlamaIndex, CrewAI, etc.) — not just Strands.

This PR makes the provider framework-agnostic by routing on obs.type (universal across all frameworks in Langfuse) with a Strands-specific fallback for backward compatibility.

Changes

  • langfuse_provider.py — Multi-framework observation routing:
  • _convert_observation(): Route by universal obs.type (GENERATION → InferenceSpan, TOOL → ToolExecutionSpan, CHAIN/AGENT root → AgentInvocationSpan) with Strands SPAN name-based fallback preserved
  • _convert_tool_execution(): Handle both Strands format (obs.input.name) and LangChain/universal format (obs.name + obs.input as arguments)
  • _parse_tool_result(): Support LangChain ToolMessage format ({"content": "...", "type": "tool"})
  • _convert_message(): Parse LangChain tool_calls field on assistant messages
  • _extract_user_prompt(): Handle LangChain CHAIN formats ({"input": "..."}, {"messages": [...]}) and Strands message-list format via OTEL ([{"role": "user", "content": '[{"text": "..."}]'}])
  • _extract_agent_response(): Handle LangChain CHAIN output formats ({"output": "..."}, {"messages": [...]}) and Strands message-list output format
  • _extract_text_from_content(): New helper to unwrap Strands content (plain string, JSON-encoded [{"text": "..."}], or parsed list)
  • pyproject.toml: Cap langfuse dependency at <4

Related Issues

#91
#159

Documentation PR

N/A

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@poshinchen poshinchen force-pushed the feat/mappers-langfuse-change branch from 908985f to 51db383 Compare March 23, 2026 00:26
@poshinchen poshinchen changed the title Feat/mappers langfuse change feat(mappers) Feat/mappers langfuse change to support newer version of langfuse Mar 23, 2026
@poshinchen poshinchen changed the title feat(mappers) Feat/mappers langfuse change to support newer version of langfuse feat(mappers): Feat/mappers langfuse change to support newer version of langfuse Mar 23, 2026
@poshinchen poshinchen changed the title feat(mappers): Feat/mappers langfuse change to support newer version of langfuse feat(mappers): langfuse provider changes to support newer version of langfuse Mar 23, 2026
@poshinchen poshinchen force-pushed the feat/mappers-langfuse-change branch from 51db383 to 5f71df9 Compare March 26, 2026 17:31
@poshinchen poshinchen force-pushed the feat/mappers-langfuse-change branch from 5f71df9 to 4b82389 Compare March 26, 2026 17:55
pyproject.toml Outdated
]

langfuse = ["langfuse>=2.0.0,<3"]
langfuse = ["langfuse>=2.0.0,<5"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a wide range. Also, my understanding is that the versions have drastic differences which would be incompatible with evals sdk (one of the reasons we introduced this PR). I would recommend a range of: langfuse>=4.0.0,<5

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would be fine with langfuse>=3,< 5, since it basically means that older version of langfuse will be deprecated. v2/3 has similar concept/component, but v3/v4 has some major diffs and I prefer to keep both versions.

@poshinchen poshinchen force-pushed the feat/mappers-langfuse-change branch from 4b82389 to b7c3b1b Compare March 26, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants