Repository navigation
feat(ai): make the agent observable through OTel GenAI conventions #1616
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
ambiguous-pointer
wants to merge
7
commits into
apache:ai
Choose a base branch
from
ambiguous-pointer:feat/ai_otel_genai
base: ai
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,176
−124
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f1ba3e3
feat(ai): make the agent observable through OTel GenAI conventions
ambiguous-pointer 8396005
fix(ai): record only the answer the user received, and align the trac…
Vent-Code 60a4a20
fix(ai): apply the capture policies to the whole trace
ambiguous-pointer 5a19554
fix(ai): register the reasoning model and keep the reasoning out of t…
ambiguous-pointer 862ff8b
merge(ai): take the upstream sensitive data boundaries into the traci…
ambiguous-pointer ecb03f3
fix(ai): address the review findings of the tracing hook
ambiguous-pointer 7609165
fix(ai): record the GenAI exception event for the client operations only
ambiguous-pointer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package react | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/firebase/genkit/go/ai" | ||
| ) | ||
|
|
||
| // answerText returns the answer of a model response. | ||
| // | ||
| // Only the parts that genkit itself treats as text are joined. The reasoning | ||
| // of a thinking model is a reasoning part, and a response that carries | ||
| // nothing but the reasoning has no answer to deliver. | ||
| // | ||
| // genkit's Message.Text() returns the text of a single part without looking | ||
| // at its kind, so the reasoning of such a response would be delivered to the | ||
| // user as the answer. It would also bypass the capture policy, because the | ||
| // policy acts on the parts of a trace and never sees the answer. | ||
| func answerText(resp *ai.ModelResponse) string { | ||
| if resp == nil || resp.Message == nil { | ||
| return "" | ||
| } | ||
| var sb strings.Builder | ||
| for _, part := range resp.Message.Content { | ||
| if part == nil { | ||
| continue | ||
| } | ||
| if part.IsText() || part.IsData() { | ||
| sb.WriteString(part.Text) | ||
| } | ||
| } | ||
| return sb.String() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package react | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/firebase/genkit/go/ai" | ||
| ) | ||
|
|
||
| // TestAnswerTextIgnoresTheReasoning makes sure the reasoning of a thinking | ||
| // model is not delivered as the answer. | ||
| // | ||
| // genkit's Message.Text() returns the text of a single part without looking | ||
| // at its kind, so a response that carries nothing but the reasoning would be | ||
| // delivered to the user as the answer, and it would bypass the capture | ||
| // policy that is meant to keep the reasoning out of the trace. | ||
| func TestAnswerTextIgnoresTheReasoning(t *testing.T) { | ||
| response := &ai.ModelResponse{ | ||
| Message: ai.NewMessage(ai.RoleModel, nil, ai.NewReasoningPart("chain of thought", nil)), | ||
| } | ||
| if got := answerText(response); got != "" { | ||
| t.Fatalf("answer of a reasoning only response = %q, want it to be empty", got) | ||
| } | ||
| } | ||
|
|
||
| // TestAnswerTextReturnsTheTextParts makes sure the answer of a response that | ||
| // carries a reasoning part as well is the text of the response. | ||
| func TestAnswerTextReturnsTheTextParts(t *testing.T) { | ||
| message := ai.NewMessage(ai.RoleModel, nil) | ||
| message.Content = append(message.Content, ai.NewReasoningPart("chain of thought", nil)) | ||
| message.Content = append(message.Content, ai.NewTextPart("the answer")) | ||
| response := &ai.ModelResponse{Message: message} | ||
| if got := answerText(response); got != "the answer" { | ||
| t.Fatalf("answer = %q, want %q", got, "the answer") | ||
| } | ||
| } | ||
|
|
||
| // TestAnswerTextOfAnEmptyResponse makes sure a response without a message | ||
| // does not panic. | ||
| func TestAnswerTextOfAnEmptyResponse(t *testing.T) { | ||
| if got := answerText(nil); got != "" { | ||
| t.Fatalf("answer of a missing response = %q, want it to be empty", got) | ||
| } | ||
| if got := answerText(&ai.ModelResponse{}); got != "" { | ||
| t.Fatalf("answer of a response without a message = %q, want it to be empty", got) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.