Skip to content

feat: support Ark context management and reliable inline-image tracing#667

Open
zakahan wants to merge 3 commits into
volcengine:mainfrom
zakahan:feat/responses-context-and-inline-image-tracing
Open

feat: support Ark context management and reliable inline-image tracing#667
zakahan wants to merge 3 commits into
volcengine:mainfrom
zakahan:feat/responses-context-and-inline-image-tracing

Conversation

@zakahan

@zakahan zakahan commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds two complementary improvements for Ark Responses workloads and multimodal observability:

  1. Pass Ark Responses context_management configuration through VeADK without filtering it out.
  2. Make inline-image TOS uploads honor runtime credentials and bucket configuration while remaining fail-open when observability storage is unavailable.

Ark Responses context management

VeADK already accepts provider-specific options through Agent.model_extra_config, but request_reorganization_by_ark() filters the final Ark request through ark_supported_fields. Because context_management was not in that allowlist, valid user configuration was removed before reaching the Ark SDK.

This PR:

  • Adds context_management to the Ark request allowlist.
  • Preserves the configured edit list unchanged, including clear_thinking and clear_tool_uses policies.
  • Verifies that Agent forwards the configuration to an Ark Responses model.
  • Verifies that Ark request reorganization retains the complete structure.
  • Raises the minimum volcengine-python-sdk version to 5.0.36, the first version with formal Responses context-management request types and request serialization support.

No context-management policy is enabled by default. Applications remain responsible for selecting supported models and configuring edit policies through model_extra_config.

Example:

agent = Agent(
    enable_responses=True,
    model_extra_config={
        "context_management": {
            "edits": [
                {
                    "type": "clear_thinking",
                    "keep": {"type": "thinking_turns", "value": 1},
                },
                {
                    "type": "clear_tool_uses",
                    "trigger": {"type": "tool_uses", "value": 30},
                    "keep": {"type": "tool_uses", "value": 20},
                },
            ]
        }
    },
)

Inline-image TOS observability

When upload_inline_data_to_tos is enabled, VeADK uploads inline media before the model call and stores a signed TOS URL in inline_data.display_name for tracing. The previous default constructor argument always supplied veadk-default-bucket, which prevented DATABASE_TOS_BUCKET from selecting an application-owned bucket. The upload API also returned no status, so the runner could assign a signed URL without knowing whether the object had actually been stored.

This PR:

  • Resolves the TOS bucket in the following order:
    1. Explicit bucket_name argument.
    2. DATABASE_TOS_BUCKET.
    3. DEFAULT_TOS_BUCKET_NAME.
  • Reads temporary STS credentials from VOLCENGINE_SESSION_TOKEN when no explicit session token is supplied.
  • Changes async_upload_bytes() to return True only after put_object succeeds and False when bucket preparation or upload fails.
  • Generates and records the signed URL only after a confirmed upload.
  • Keeps inline-image preprocessing fail-open: failed uploads and TOS exceptions are logged, the original inline data remains unchanged, and the model execution path continues.

Explicit constructor values continue to take precedence over environment configuration. The existing signed-URL format and expiration behavior are unchanged.

Tests

Added regression coverage for:

  • Agent-to-Ark forwarding of context_management.
  • Ark request reorganization preserving context-management edit policies.
  • Environment-based TOS bucket and STS token resolution.
  • Explicit bucket precedence.
  • Successful and failed asynchronous upload status.
  • Fail-open inline-image behavior when TOS returns a failure status.
  • Fail-open inline-image behavior when the TOS upload raises an exception.

Validation:

22 passed
Ruff check: passed
Ruff format check: passed
git diff --check: passed

@zakahan
zakahan force-pushed the feat/responses-context-and-inline-image-tracing branch from 22a1f7a to 4eeaa52 Compare July 16, 2026 03:33
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