Skip to content

Commit b164e41

Browse files
committed
fix lint
1 parent 81b255a commit b164e41

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

langfuse/_client/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def start_as_current_span(
366366
"retriever",
367367
"embedding",
368368
]
369-
],
369+
] = None,
370370
) -> _AgnosticContextManager[LangfuseSpan]:
371371
"""Create a new span and set it as the current span in a context manager.
372372
@@ -695,9 +695,8 @@ def _get_span_class(
695695
"retriever",
696696
"embedding",
697697
],
698-
):
698+
) -> type:
699699
"""Get the appropriate span class based on as_type."""
700-
# TODO: make it case insensitive
701700
if as_type == "agent":
702701
return LangfuseAgent
703702
elif as_type == "tool":

langfuse/_client/observe.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,6 @@ async def async_wrapper(*args: Tuple[Any], **kwargs: Dict[str, Any]) -> Any:
303303
with _set_current_public_key(public_key):
304304
langfuse_client = get_client(public_key=public_key)
305305

306-
# Use consolidated as_type parameter
307-
final_obs_type = as_type
308-
309306
context_manager: Optional[
310307
Union[
311308
_AgnosticContextManager[LangfuseGeneration],
@@ -319,13 +316,13 @@ async def async_wrapper(*args: Tuple[Any], **kwargs: Dict[str, Any]) -> Any:
319316
input=input,
320317
end_on_exit=False, # when returning a generator, closing on exit would be to early
321318
)
322-
if final_obs_type in ("generation", "GENERATION")
319+
if as_type == "generation"
323320
else langfuse_client.start_as_current_span(
324321
name=final_name,
325322
trace_context=trace_context,
326323
input=input,
327324
end_on_exit=False, # when returning a generator, closing on exit would be to early
328-
as_type=final_obs_type,
325+
as_type=as_type,
329326
)
330327
)
331328
if langfuse_client
@@ -413,9 +410,6 @@ def sync_wrapper(*args: Any, **kwargs: Any) -> Any:
413410
with _set_current_public_key(public_key):
414411
langfuse_client = get_client(public_key=public_key)
415412

416-
# Use consolidated as_type parameter
417-
final_obs_type = as_type
418-
419413
context_manager: Optional[
420414
Union[
421415
_AgnosticContextManager[LangfuseGeneration],
@@ -429,13 +423,13 @@ def sync_wrapper(*args: Any, **kwargs: Any) -> Any:
429423
input=input,
430424
end_on_exit=False, # when returning a generator, closing on exit would be to early
431425
)
432-
if final_obs_type in ("generation", "GENERATION")
426+
if as_type == "generation"
433427
else langfuse_client.start_as_current_span(
434428
name=final_name,
435429
trace_context=trace_context,
436430
input=input,
437431
end_on_exit=False, # when returning a generator, closing on exit would be to early
438-
as_type=final_obs_type,
432+
as_type=as_type,
439433
)
440434
)
441435
if langfuse_client

langfuse/_client/span.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ def update(
13331333
class LangfuseAgent(LangfuseGraphObservation):
13341334
"""Specialized span for agent observations in agentic workflows."""
13351335

1336-
def __init__(self, **kwargs):
1336+
def __init__(self, **kwargs) -> None:
13371337
"""Initialize a new LangfuseAgent span."""
13381338
kwargs["observation_type"] = "agent"
13391339
super().__init__(**kwargs)
@@ -1342,7 +1342,7 @@ def __init__(self, **kwargs):
13421342
class LangfuseTool(LangfuseGraphObservation):
13431343
"""Specialized span for tool observations in agentic workflows."""
13441344

1345-
def __init__(self, **kwargs):
1345+
def __init__(self, **kwargs) -> None:
13461346
"""Initialize a new LangfuseTool span."""
13471347
kwargs["observation_type"] = "tool"
13481348
super().__init__(**kwargs)
@@ -1351,7 +1351,7 @@ def __init__(self, **kwargs):
13511351
class LangfuseChain(LangfuseGraphObservation):
13521352
"""Specialized span for chain observations in agentic workflows."""
13531353

1354-
def __init__(self, **kwargs):
1354+
def __init__(self, **kwargs) -> None:
13551355
"""Initialize a new LangfuseChain span."""
13561356
kwargs["observation_type"] = "chain"
13571357
super().__init__(**kwargs)
@@ -1360,7 +1360,7 @@ def __init__(self, **kwargs):
13601360
class LangfuseRetriever(LangfuseGraphObservation):
13611361
"""Specialized span for retriever observations in agentic workflows."""
13621362

1363-
def __init__(self, **kwargs):
1363+
def __init__(self, **kwargs) -> None:
13641364
"""Initialize a new LangfuseRetriever span."""
13651365
kwargs["observation_type"] = "retriever"
13661366
super().__init__(**kwargs)
@@ -1369,7 +1369,7 @@ def __init__(self, **kwargs):
13691369
class LangfuseEmbedding(LangfuseGraphObservation):
13701370
"""Specialized span for embedding observations in agentic workflows."""
13711371

1372-
def __init__(self, **kwargs):
1372+
def __init__(self, **kwargs) -> None:
13731373
"""Initialize a new LangfuseEmbedding span."""
13741374
kwargs["observation_type"] = "embedding"
13751375
super().__init__(**kwargs)

tests/test_manual_graph_instrumentation.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import time
22

33
from langfuse import Langfuse, observe
4-
from tests.api_wrapper import LangfuseAPI
54
from tests.utils import create_uuid, get_api
65

76

@@ -35,15 +34,15 @@ def end_agent():
3534
# Run the workflow within a trace context
3635
with langfuse.start_as_current_span(
3736
name="agent_workflow", as_type="agent"
38-
) as root_span:
37+
):
3938
langfuse.update_current_trace(name=trace_name)
4039

4140
start_result = start_agent()
4241
process_result = process_agent()
4342
tool_result = tool_call()
4443
end_result = end_agent()
4544

46-
workflow_result = {
45+
_workflow_result = {
4746
"start": start_result,
4847
"process": process_result,
4948
"tool": tool_result,
@@ -122,7 +121,7 @@ def end_agent():
122121
# Execute the parallel workflow
123122
with langfuse.start_as_current_span(
124123
name="parallel_workflow", as_type="span"
125-
) as root_span:
124+
):
126125
langfuse.update_current_trace(name=trace_name)
127126
start_result = start_agent()
128127

@@ -143,7 +142,7 @@ def end_agent():
143142

144143
end_result = end_agent()
145144

146-
workflow_result = {
145+
_workflow_result = {
147146
"start": start_result,
148147
"tools": tool_results,
149148
"end": end_result,
@@ -171,8 +170,6 @@ def end_agent():
171170
for obs in all_observations
172171
if obs.type in ["agent", "tool", "AGENT", "TOOL"]
173172
]
174-
print(all_observations)
175-
print(graph_observations)
176173

177174
# Should have: start_agent (1) + 3 tools (3) + end_agent (1) = 5 total
178175
expected_count = 5
@@ -194,6 +191,3 @@ def end_agent():
194191
), f"Expected 3 tool observations, got {len(tool_observations)}"
195192

196193

197-
if __name__ == "__main__":
198-
test_observe_type_agent_instrumentation()
199-
test_observe_type_parallel_tool_execution()

0 commit comments

Comments
 (0)