Skip to content

Conversation

@zakahan
Copy link
Collaborator

@zakahan zakahan commented Aug 6, 2025

No description provided.

@cuericlee cuericlee requested a review from Copilot August 6, 2025 03:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where agent tracers were not properly initialized in the VeFaaS environment by ensuring tracer callbacks are updated after extending the tracers list.

  • Extracts tracer callback setup logic into a reusable update_tracers_callback() method
  • Adds deduplication logic to prevent duplicate callback registration
  • Calls the new method after extending tracers in the VeFaaS template to ensure proper initialization

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
veadk/cli/services/vefaas/template/src/app.py Calls update_tracers_callback() after extending agent tracers
veadk/agent.py Refactors tracer callback setup into a reusable method with deduplication

Comment on lines +128 to +134
for tracer in self.tracers:
# Add tracer callbacks if not already added
if tracer.llm_metrics_hook not in self.before_model_callback:
self.before_model_callback.append(tracer.llm_metrics_hook)
if tracer.token_metrics_hook not in self.after_model_callback:
self.after_model_callback.append(tracer.token_metrics_hook)

Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using not in for list membership checking has O(n) complexity. Consider using a set to track added callbacks for O(1) lookups, especially if the number of tracers could be large.

Suggested change
for tracer in self.tracers:
# Add tracer callbacks if not already added
if tracer.llm_metrics_hook not in self.before_model_callback:
self.before_model_callback.append(tracer.llm_metrics_hook)
if tracer.token_metrics_hook not in self.after_model_callback:
self.after_model_callback.append(tracer.token_metrics_hook)
before_set = set(self.before_model_callback)
after_set = set(self.after_model_callback)
for tracer in self.tracers:
# Add tracer callbacks if not already added
if tracer.llm_metrics_hook not in before_set:
self.before_model_callback.append(tracer.llm_metrics_hook)
before_set.add(tracer.llm_metrics_hook)
if tracer.token_metrics_hook not in after_set:
self.after_model_callback.append(tracer.token_metrics_hook)
after_set.add(tracer.token_metrics_hook)

Copilot uses AI. Check for mistakes.
Comment on lines +128 to +134
for tracer in self.tracers:
# Add tracer callbacks if not already added
if tracer.llm_metrics_hook not in self.before_model_callback:
self.before_model_callback.append(tracer.llm_metrics_hook)
if tracer.token_metrics_hook not in self.after_model_callback:
self.after_model_callback.append(tracer.token_metrics_hook)

Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using not in for list membership checking has O(n) complexity. Consider using a set to track added callbacks for O(1) lookups, especially if the number of tracers could be large.

Suggested change
for tracer in self.tracers:
# Add tracer callbacks if not already added
if tracer.llm_metrics_hook not in self.before_model_callback:
self.before_model_callback.append(tracer.llm_metrics_hook)
if tracer.token_metrics_hook not in self.after_model_callback:
self.after_model_callback.append(tracer.token_metrics_hook)
before_set = set(self.before_model_callback)
after_set = set(self.after_model_callback)
for tracer in self.tracers:
# Add tracer callbacks if not already added
if tracer.llm_metrics_hook not in before_set:
self.before_model_callback.append(tracer.llm_metrics_hook)
before_set.add(tracer.llm_metrics_hook)
if tracer.token_metrics_hook not in after_set:
self.after_model_callback.append(tracer.token_metrics_hook)
after_set.add(tracer.token_metrics_hook)

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@cuericlee cuericlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@cuericlee cuericlee merged commit 3d956b9 into volcengine:main Aug 6, 2025
4 checks passed
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.

2 participants