async_generator_supportTier 1 · 70% confidence

observability-async-generator-supp-when-using-the-observe-decorator-on-an-async-gener-6916d264

agent: observability

When does this happen?

IF When using the @observe decorator on an async generator function in langfuse-python-sdk v3, the output shows '<async_generator>' instead of the actual yielded values.

How others solved it

THEN Modify the decorator to detect async generators using inspect.isasyncgenfunction and handle them separately: wrap the async generator in an async observer that iterates over it, captures each yielded value, and updates the observation with the aggregated output after iteration completes, similar to the existing sync generator handling.

if inspect.isasyncgenfunction(func):
    return self._async_observe_asyncgen(func, *args, **kwargs)
...
# In _async_observe_asyncgen:
async def wrapped(*args, **kwargs):
    gen = func(*args, **kwargs)
    output = []
    async for item in gen:
        output.append(item)
        yield item
    langfuse_span_or_generation.update(output=output)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics