Skip to content

Conversation

@shuningc
Copy link
Contributor

Adding a separate workflow agent instrumentation mechanism with a wrapper function:
✅ Dual instrumentation paths for backward compatibility
✅ Non-invasive: Uses monkey-patching, no code changes needed
✅ Async-aware: Background task doesn't block user code
✅ Context propagation: Manual for workflows, automatic for callbacks
✅ Shared TelemetryHandler: Both paths use same handler instance

User code:
agent = ReActAgent(tools=[...])
handler = agent.run("Calculate 5*3+2")

↓ (intercepted by wrap_agent_run)

wrap_agent_run():
Line 137: handler = wrapped(*args, **kwargs)

└─→ Calls original ReActAgent.run()

└─→ Returns WorkflowHandler
(contains stream of events)

Line 159: await instrumentor.instrument_workflow_handler(handler, ...)

└─→ Pass handler to instrumentor

Line 169: return handler # Return to user

└─→ User can await it

instrument_workflow_handler(workflow_handler):
Line 43: async for event in workflow_handler.stream_events():
↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
THIS IS THE CONSUMPTION!

       We're iterating through the event stream
       that the WorkflowHandler provides

- Add embedding event handlers (_handle_embedding_start, _handle_embedding_end)
- Extract model name, input texts, and dimension count from embedding events
- Create vendor_detection.py module with VendorRule-based provider detection
- Support 13+ embedding providers (OpenAI, Azure, AWS, Google, Cohere, etc.)
- Add test_embedding_instrumentation.py with single and batch embedding tests
- Update README with embedding documentation and provider list
- Tested successfully with OpenAI embeddings API
@shuningc shuningc requested review from a team as code owners November 26, 2025 23:41
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.

1 participant