Skip to content

Issue 3890 Tool call results returned via ChatResponse lack identification metadata #3944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wilocu
Copy link

@wilocu wilocu commented Jul 29, 2025

#3890
Summary
This PR adds the ability to distinguish between model-generated and tool-generated responses in OllamaChatModel by adding source metadata to
ChatResponse objects. Frontend developers can now easily identify the origin of each response through standardized metadata fields.

Changes Made
Core Implementation:

  • OllamaChatModel.java: Added source metadata constants and modified internalStream() and internalCall() methods to include source="model" in
    generation metadata
  • ToolExecutionResult.java: Added source metadata constants and enhanced buildGenerations() to include source="tool" for tool-generated
    responses

Testing:

  • OllamaChatModelTests.java: Added unit test to verify source metadata creation
  • ToolExecutionResultTests.java: Added unit test to verify tool response source metadata
  • OllamaChatModelIT.java: Added integration test to verify source metadata in real responses

Usage
Developers can now identify response sources:
ChatResponse response = chatModel.call(new Prompt("Hello"));
String source = (String) response.getResult().getMetadata().get("source");
// Returns: "model" for model-generated responses
// Returns: "tool" for tool-generated responses

Testing

  • All existing tests continue to pass
  • New unit tests verify metadata creation for both model and tool responses
  • Integration test confirms functionality with real Ollama responses
  • Build passes with ./mvnw clean package -DskipTests on modified modules

This implementation provides a clean, maintainable solution that enables frontend developers to easily differentiate between response sources
while maintaining full backward compatibility.

Signed-off-by: Mattia Pasetto [email protected]

I am still pretty new to contributions, please double check and let me know of any errors.

Signed-off-by: Mattia Pasetto <[email protected]>
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