Skip to content

Fixes #532#1412

Open
alexheifetz wants to merge 1 commit intomainfrom
issue/532
Open

Fixes #532#1412
alexheifetz wants to merge 1 commit intomainfrom
issue/532

Conversation

@alexheifetz
Copy link
Contributor

This pull request introduces a new instrumentation layer for Spring AI chat model calls, enabling automatic emission of ChatModelCallEvent with the fully augmented prompt at the exact point the model is invoked. The change eliminates manual event emission at multiple call sites and ensures accurate event capture. The implementation uses a decorator (InstrumentedChatModel) and updates the client creation logic to support this. Comprehensive tests verify correct behavior and interface compliance.

Instrumentation and event emission improvements:

  • Added InstrumentedChatModel class to wrap ChatModel and emit a ChatModelCallEvent with the final prompt during call() invocation, ensuring domain context is captured and event emission is centralized. (embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/support/springai/InstrumentedChatModel.kt)
  • Updated ChatClientLlmOperations.createChatClient to accept an optional llmRequestEvent and use InstrumentedChatModel when provided, replacing manual event emission at each call site with transparent instrumentation. (embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/support/springai/ChatClientLlmOperations.kt) [1] [2] [3] [4] [5]
  • Removed redundant manual event emission code from multiple methods in ChatClientLlmOperations, as instrumentation is now handled by the decorator. (embabel-agent-api/src/main/kotlin/com/embabel/agent/spi/support/springai/ChatClientLlmOperations.kt) [1] [2] [3]

Testing and validation:

  • Added a comprehensive test suite for InstrumentedChatModel, verifying correct delegation, event emission, error propagation, and interface contract compliance. (embabel-agent-api/src/test/kotlin/com/embabel/agent/spi/support/springai/InstrumentedChatModelTest.kt)

@sonarqubecloud
Copy link

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