test_case_id: "builtin_load_artifact_specific_versions_001"
description: |
  Tests the 'load_artifact' tool by loading different, specific integer versions
  of the same artifact.
tags: ["all","agent","tools","builtin_artifact_tools"]
skip_intermediate_events: true

setup_artifacts:
  # Version 0
  - filename: "multiversion_doc.txt"
    content: "Content v0" # Length 10
    mime_type: "text/plain"
    metadata:
      description: "Version 0 of multiversion document"
      version_marker: "v0"
      mime_type: "text/plain"
      size_bytes: 10

  # Version 1
  - filename: "multiversion_doc.txt" # Same filename creates a new version
    content: "Content v1 - updated" # Length 20
    mime_type: "text/plain"
    metadata:
      description: "Version 1 of multiversion document - UPDATED"
      version_marker: "v1_updated"
      mime_type: "text/plain"
      size_bytes: 20

gateway_input:
  target_agent_name: "TestAgent"
  user_identity: "declarative_load_versions_tester@example.com"
  a2a_parts:
    - type: "text"
      text: "Please load version 0 and then version 1 of 'multiversion_doc.txt'."
  external_context:
    a2a_session_id: "session_load_versions_artifact_001"

llm_interactions:
  # Step 1: LLM calls load_artifact for version 0
  - step_id: "llm_calls_load_artifact_v0"
    static_response:
      id: "chatcmpl-load-versions-v0"
      object: "chat.completion"
      model: "test-llm-model"
      choices:
        - message:
            role: "assistant"
            tool_calls:
              - id: "tool_call_load_v0"
                type: "function"
                function:
                  name: "load_artifact"
                  arguments: '{"filename": "multiversion_doc.txt", "version": 0}'
          finish_reason: "tool_calls"

  # Step 2: LLM receives v0 result, then calls load_artifact for version 1
  - step_id: "llm_calls_load_artifact_v1"
    expected_request: # After load_artifact v0 tool call
      expected_tool_responses_in_llm_messages:
        - tool_call_id_matches_prior_request_index: 0
          response_json_matches:
            status: "success"
            filename: "multiversion_doc.txt"
            version: 0
            content: "Content v0"
            mime_type: "text/plain"
            size_bytes: 10
    static_response:
      id: "chatcmpl-load-versions-v1"
      object: "chat.completion"
      model: "test-llm-model"
      choices:
        - message:
            role: "assistant"
            tool_calls:
              - id: "tool_call_load_v1"
                type: "function"
                function:
                  name: "load_artifact"
                  arguments: '{"filename": "multiversion_doc.txt", "version": 1}'
          finish_reason: "tool_calls"

  # Step 3: LLM receives v1 result and formulates final response
  - step_id: "llm_final_response_after_version_loads"
    # Removing the expected_request block for this step to avoid issues with
    # cumulative tool response history and the test runner's current assertion logic
    # for tool_call_id_matches_prior_request_index.
    # The success of the second tool call (load_v1) is implicitly tested by the
    # LLM's ability to formulate the correct final response, and by assert_artifact_state.
    static_response:
      id: "chatcmpl-load-versions-final"
      object: "chat.completion"
      model: "test-llm-model"
      choices:
        - message:
            role: "assistant"
            content: "Loaded v0: 'Content v0'. Loaded v1: 'Content v1 - updated'."
          finish_reason: "stop"

expected_gateway_output:
  - type: "final_response"
    content_parts:
      - type: "text"
        text_exact: "Loaded v0: 'Content v0'. Loaded v1: 'Content v1 - updated'."
    task_state: "completed"
    # Assert state of the setup artifacts to ensure they were not modified
    assert_artifact_state:
      - filename: "multiversion_doc.txt" # Version 0
        user_id: "declarative_load_versions_tester@example.com"
        session_id: "session_load_versions_artifact_001"
        version: 0
        expected_content_text: "Content v0"
        expected_metadata_contains:
          description: "Version 0 of multiversion document"
          version_marker: "v0"
          mime_type: "text/plain"
          size_bytes: 10
      - filename: "multiversion_doc.txt" # Version 1
        user_id: "declarative_load_versions_tester@example.com"
        session_id: "session_load_versions_artifact_001"
        version: 1
        expected_content_text: "Content v1 - updated"
        expected_metadata_contains:
          description: "Version 1 of multiversion document - UPDATED"
          version_marker: "v1_updated"
          mime_type: "text/plain"
          size_bytes: 20
