Skip to content

fix(ai): remove setting of GEN_AI_AGENT_NAME from langchain#5728

Open
harryautomazione wants to merge 2 commits intogetsentry:masterfrom
harryautomazione:fix/issue-5719
Open

fix(ai): remove setting of GEN_AI_AGENT_NAME from langchain#5728
harryautomazione wants to merge 2 commits intogetsentry:masterfrom
harryautomazione:fix/issue-5719

Conversation

@harryautomazione
Copy link

Description

This PR removes the setting of SPANDATA.GEN_AI_AGENT_NAME from several places in the langchain integration, as pulling it from request parameters (like run_name) was identified as semantically incorrect.

The setting in on_llm_start was already removed in PR #5705. This completes the removal for other areas to fully resolve the issue.

Changes

  • Removed assignment of SPANDATA.GEN_AI_AGENT_NAME in on_chat_model_start.
  • Removed assignment in on_tool_start.
  • Removed assignment in _wrap_agent_executor_invoke.
  • Removed assignment in _wrap_agent_executor_stream.

Resolves: #5719

@harryautomazione harryautomazione requested a review from a team as a code owner March 20, 2026 19:18
@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (asgi) Add option to disable suppressing chained exceptions by alexander-alderman-webb in #5714
  • (logging) Separate ignore lists for events/breadcrumbs and sentry logs by sl0thentr0py in #5698

Bug Fixes 🐛

Anthropic

  • Set exception info on streaming span when applicable by alexander-alderman-webb in #5683
  • Patch AsyncStream.close() and AsyncMessageStream.close() to finish spans by alexander-alderman-webb in #5675
  • Patch Stream.close() and MessageStream.close() to finish spans by alexander-alderman-webb in #5674

Other

  • (ai) Remove setting of GEN_AI_AGENT_NAME from langchain by harryautomazione in #5728

Documentation 📚

  • Add note on AI PRs to CONTRIBUTING.md by sentrivana in #5696

Internal Changes 🔧

  • Add -latest alias for each integration test suite by sentrivana in #5706
  • Use date-based branch names for toxgen PRs by sentrivana in #5704
  • 🤖 Update test matrix with new releases (03/19) by github-actions in #5703
  • Add client report tests for span streaming by sentrivana in #5677

Other

  • Update CHANGELOG.md by sentrivana in #5685

🤖 This preview updates automatically when you update the PR.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

name=f"invoke_agent {agent_name}" if agent_name else "invoke_agent",
origin=LangchainIntegration.origin,
) as span:
_push_agent(agent_name)
Copy link

Choose a reason for hiding this comment

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

Empty finally block with stale misleading comment

Low Severity

The try/finally block in _wrap_agent_executor_invoke is now empty — the finally clause only contains a stale comment ("Ensure agent is popped even if an exception occurs") with no actual code. The entire try/finally construct is now dead scaffolding that adds indentation and a misleading comment suggesting cleanup is happening when it isn't. The try/finally wrapper can be removed entirely.

Fix in Cursor Fix in Web



# Contextvar to track agent names in a stack for re-entrant agent support
_agent_stack: "contextvars.ContextVar[Optional[List[Optional[str]]]]" = (
Copy link

Choose a reason for hiding this comment

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

Stale contextvar comment above unrelated function definition

Low Severity

The comment # Contextvar to track agent names in a stack for re-entrant agent support at line 156 is now orphaned — it previously described _agent_stack and the related _push_agent/_pop_agent/_get_current_agent functions that were all removed. It now misleadingly sits directly above the unrelated _get_system_instructions function.

Fix in Cursor Fix in Web



# Contextvar to track agent names in a stack for re-entrant agent support
_agent_stack: "contextvars.ContextVar[Optional[List[Optional[str]]]]" = (
Copy link

Choose a reason for hiding this comment

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

Unused contextvars import after removing its only consumer

Low Severity

The import contextvars at line 1 is now unused. The only consumer was the removed _agent_stack context variable. No other reference to contextvars exists in the file.

Fix in Cursor Fix in Web

…mand, parameter name, and attribute

- Change install command to include [pydantic_ai] extra
- Change result_type to output_type in example
- Change result.data to result.output in example

This ensures the docstring matches the current Pydantic AI API and correct installation instructions.
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