Alejandro Rodríguez activity https://gitlab.com/alejandro 2026-03-17T16:35:16Z tag:gitlab.com,2026-03-17:5213837904 Alejandro Rodríguez approved merge request !4906: chore(mypy): reduce mypy errors at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Sugges... 2026-03-17T16:35:16Z alejandro Alejandro Rodríguez [email protected]

What does this merge request do and why?

This removes mypy errors in the following files.

  • ai_gateway/api/middleware/base.py
  • ai_gateway/code_suggestions/processing/ops.py
  • ai_gateway/instrumentators/model_requests.py
  • ai_gateway/integrations/amazon_q/test_chat.py
$ make check-mypy
--snip--
ai_gateway/code_suggestions/processing/ops.py:312: error: Argument 1 to "map" has incompatible type "type[tuple[_T_co, ...]]"; expected "Callable[[ndarray[tuple[Any, ...], dtype[signedinteger[_32Bit | _64Bit]]]], ndarray[tuple[Any, ...], dtype[signedinteger[_32Bit | _64Bit]]]]"  [arg-type]
ai_gateway/code_suggestions/processing/ops.py:314: error: Incompatible return value type (got "list[ndarray[tuple[Any, ...], dtype[signedinteger[_32Bit | _64Bit]]]]", expected "list[tuple[Any, ...]]")  [return-value]
ai_gateway/api/middleware/base.py:80: error: Argument 1 to "float" has incompatible type "str | None"; expected "str | Buffer | SupportsFloat | SupportsIndex"  [arg-type]
ai_gateway/api/middleware/base.py:111: error: Incompatible types in assignment (expression has type "Any | BaseExceptionGroup[Any]", variable has type "Exception")  [assignment]
ai_gateway/api/middleware/base.py:120: error: Argument 1 to "get_path_with_query_string" has incompatible type "MutableMapping[str, Any]"; expected "HTTPScope | WebSocketScope"  [arg-type]
ai_gateway/api/middleware/base.py:121: error: Item "None" of "Address | None" has no attribute "host"  [union-attr]
ai_gateway/api/middleware/base.py:122: error: Item "None" of "Address | None" has no attribute "port"  [union-attr]
ai_gateway/instrumentators/model_requests.py:165: error: Incompatible types in assignment (expression has type "float", variable has type "None")  [assignment]
ai_gateway/instrumentators/model_requests.py:278: error: Unsupported operand types for - ("float" and "None")  [operator]
ai_gateway/integrations/amazon_q/test_chat.py:140: error: Need type annotation for "event"  [var-annotated]
ai_gateway/integrations/amazon_q/test_chat.py:253: error: Missing named argument "shape" for "ReferenceSpan"  [call-arg]
ai_gateway/integrations/amazon_q/test_chat.py:346: error: Argument after ** must be a mapping, not "Collection[str]"  [arg-type]
ai_gateway/integrations/amazon_q/test_chat.py:381: error: Dict entry 0 has incompatible type "str": "str"; expected "str": "dict[str, str]"  [dict-item]
ai_gateway/integrations/amazon_q/test_chat.py:382: error: Dict entry 1 has incompatible type "str": "str"; expected "str": "dict[str, str]"  [dict-item]
ai_gateway/integrations/amazon_q/test_chat.py:383: error: Dict entry 2 has incompatible type "str": "str"; expected "str": "dict[str, str]"  [dict-item]
ai_gateway/integrations/amazon_q/test_chat.py:384: error: Dict entry 3 has incompatible type "str": "str"; expected "str": "dict[str, str]"  [dict-item]
Found 16 errors in 4 files (checked 927 source files)
make: *** [Makefile:226: check-mypy] Error 1

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
  • If this change requires executor implementation: verified that issues/MRs exist for both Go executor and Node executor or confirmed that changes are backward-compatible and don't break existing executor functionality.
tag:gitlab.com,2026-03-17:5213788605 Alejandro Rodríguez commented on merge request !4650 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-17T16:23:49Z alejandro Alejandro Rodríguez [email protected]

@Joey_Khabie I think this could be rewritten like we did for ai_gateway/prompts/registry.py to use a single structure to keep the mapping, see !4650 (comment 3109049115)

tag:gitlab.com,2026-03-17:5213427878 Alejandro Rodríguez commented on merge request !4904 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-17T15:08:29Z alejandro Alejandro Rodríguez [email protected]

@mikolaj_wawrzyniak thanks! Great feedback. Addressed, 🏓

tag:gitlab.com,2026-03-17:5213426067 Alejandro Rodríguez commented on merge request !4904 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-17T15:08:07Z alejandro Alejandro Rodríguez [email protected]

Good point. Changed.

tag:gitlab.com,2026-03-17:5213425575 Alejandro Rodríguez commented on merge request !4904 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-17T15:08:01Z alejandro Alejandro Rodríguez [email protected]

Updated 👍

tag:gitlab.com,2026-03-17:5213423836 Alejandro Rodríguez pushed to project branch refactor-human-input at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-17T15:07:40Z alejandro Alejandro Rodríguez [email protected]

Alejandro Rodríguez (12e9dfd3) at 17 Mar 15:07

refactor: use plain strings for the HumanInput component

tag:gitlab.com,2026-03-17:5213239927 Alejandro Rodríguez commented on issue #523707 at GitLab.org / GitLab 2026-03-17T14:32:06Z alejandro Alejandro Rodríguez [email protected]

For a retrospective discussion, what could we do to prevent this in the future? In https://gitlab.com/gitlab-com/gl-security/corp/issue-tracker/-/work_items/4152 I see the project was considered for deletion because it was from a sandbox account co-created from an offboarded team member. What process was followed to establish this project was unused, and how can the AI Framework team communicate which projects it depends on? In this thread we proposed previously to move developers to dev-ai-research-0e2f8974 instead, but from the name it seems this one is also a sandbox one, so not sure it's susceptible to the same situation. We also have gitlab-ai-framework-dev, which is not a sandbox project and is managed as IaC. Would that be the preferable option?

/cc @vlad @ajaythomasinc

tag:gitlab.com,2026-03-17:5213186557 Alejandro Rodríguez commented on issue #523707 at GitLab.org / GitLab 2026-03-17T14:22:29Z alejandro Alejandro Rodríguez [email protected]

@tmrrss we restored ai-enablement-dev-69497ba7 (thanks @vlad @rnienaber!), you should be able to go back.

tag:gitlab.com,2026-03-17:5213129625 Alejandro Rodríguez approved merge request !3969: feat: add support to Anthropic's context editing feature at GitLab.org / ModelOps / AI Assisted (formerly... 2026-03-17T14:11:00Z alejandro Alejandro Rodríguez [email protected]

What does this merge request do and why?

This change adds a new "context management" feature that helps AI models handle long conversations more efficiently by automatically removing old tool usage data when the conversation gets too long.

The feature is specifically designed for Anthropic AI models and includes smart filtering - it only applies context management to Anthropic models and removes the setting for other AI providers that don't support it.

Three new workflow configurations are added (context_builder, executor, and planner) that each have different thresholds for when to start clearing old data - for example, one starts clearing when the conversation reaches 4000 input tokens and keeps only the 2 most recent tool uses.

The system includes comprehensive testing to verify that context management actually reduces the number of input tokens being processed, which should improve performance and reduce costs for long conversations. The tests simulate conversations with multiple tool interactions and confirm that enabling context management results in fewer tokens being sent to the AI model compared to keeping the full conversation history.

What is Anthropic context editing feature:

Context editing allows you to automatically manage conversation context as it grows, helping you optimize costs and stay within context window limits.

The clear_tool_uses_20250919 strategy,  When activated, the API automatically clears the oldest tool results in chronological order, replacing them with placeholder text to let Claude know the tool result was removed.

More information here: https://platform.claude.com/docs/en/build-with-claude/context-editing

Issue:

closes #1543

How to set up and validate locally

Instructions and test results see below: !3969 (comment 2912060215)

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
  • If this change requires executor implementation: verified that issues/MRs exist for both Go executor and Node executor or confirmed that changes are backward-compatible and don't break existing executor functionality.
tag:gitlab.com,2026-03-16:5210383245 Alejandro Rodríguez commented on merge request !4904 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-16T23:23:54Z alejandro Alejandro Rodríguez [email protected]

@mikolaj_wawrzyniak would you mind reviewing this MR? Related to #1429 (comment 3088609076)

tag:gitlab.com,2026-03-16:5210380178 Alejandro Rodríguez commented on merge request !4904 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-16T23:22:42Z alejandro Alejandro Rodríguez [email protected]

@GitLabDuo it appears this is not the case:

>>> from ai_gateway.prompts import jinja2_formatter
>>> jinja2_formatter("{{x}} {{y}}", x=1)
'1 '
tag:gitlab.com,2026-03-16:5210374754 Alejandro Rodríguez commented on merge request !4904 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-16T23:20:45Z alejandro Alejandro Rodríguez [email protected]

@GitLabDuo the suppression is not needed, and the linter is complaining if we leave the comment.

tag:gitlab.com,2026-03-16:5210373128 Alejandro Rodríguez commented on issue #1429 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-16T23:19:35Z alejandro Alejandro Rodríguez [email protected]

Getting the template for RequestNode

Opened !4904 for this.

tag:gitlab.com,2026-03-16:5210370369 Alejandro Rodríguez commented on merge request !4904 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-16T23:17:46Z alejandro Alejandro Rodríguez [email protected]

Unrelated to this MR, but the linter was complaining that this suppression is not needed.

tag:gitlab.com,2026-03-16:5210369723 Alejandro Rodríguez opened merge request !4904: refactor: use plain strings for the HumanInput component at GitLab.org / ModelOps / AI Assisted (formerly Ap... 2026-03-16T23:17:20Z alejandro Alejandro Rodríguez [email protected]

What does this merge request do and why?

refactor: use plain strings for the HumanInput component

This is a currently unused component, but it currently relies on extracting the jinja template from the Prompt object, which is an ability we'll remove in #1429

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
  • If this change requires executor implementation: verified that issues/MRs exist for both Go executor and Node executor or confirmed that changes are backward-compatible and don't break existing executor functionality.
tag:gitlab.com,2026-03-16:5210368900 Alejandro Rodríguez pushed new project branch refactor-human-input at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-16T23:16:48Z alejandro Alejandro Rodríguez [email protected]

Alejandro Rodríguez (ffaad031) at 16 Mar 23:16

refactor: use plain strings for the HumanInput component

tag:gitlab.com,2026-03-16:5210365185 Alejandro Rodríguez commented on merge request !4903 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-16T23:15:06Z alejandro Alejandro Rodríguez [email protected]

@halilcoban would you mind reviewing this MR? See #1429 (comment 3082788576) for more context.

tag:gitlab.com,2026-03-16:5210362438 Alejandro Rodríguez commented on merge request !4903 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-16T23:13:53Z alejandro Alejandro Rodríguez [email protected]

This is a valid concern, but one that already existed in the code, so keeping the old behavior for now in this MR.

tag:gitlab.com,2026-03-16:5210360579 Alejandro Rodríguez commented on merge request !4903 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-16T23:13:06Z alejandro Alejandro Rodríguez [email protected]

@GitLabDuo then we'll re-add it if/when needed.

tag:gitlab.com,2026-03-16:5210358338 Alejandro Rodríguez commented on merge request !4903 at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-16T23:11:59Z alejandro Alejandro Rodríguez [email protected]

@GitLabDuo self.prompt.name is always equal to self.name (or it should always be. It actually doesn't make sense in the current code that we get the name from the prompt, because the prompt file name is supposed to be human readable and may vary by model/provider), and "conversation_history": {self.name: [model_completion]} does NOT drop the history, we have a conversation_history reducer that makes state updates to it an append operation, see https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist/-/blob/316c251a5ec73bd296fab3591d4f240d0e12916b/duo_workflow_service/entities/state.py#L132-156