Skip to content

feat: Support automatic artifact storage for files generated by skill toolset scripts #5579

Closed

Description

@henrywang0314

Summary

When skill toolset scripts generate files (e.g., PDF creation, image generation, data
exports), these files are created in temporary directories and lost after execution.
There's currently no built-in mechanism to persist skill-generated files as artifacts.

Current Behavior

  • Skill scripts can generate files in temporary directories during execution
  • These files are not automatically saved as artifacts
  • SaveFilesAsArtifactsPlugin only handles user-uploaded files (inline_data)
  • Files are discarded after script execution completes

Expected Behavior

One or more of:

  1. Automatic artifact storage for skill-generated files (if returned in response)
  2. Plugin support for intercepting tool responses with file data
  3. Documentation on best practices for persisting skill-generated files
  4. Skill API extension for explicit artifact saving

Use Cases

  • PDF generation skills that need to save generated PDFs
  • Image processing skills that output images
  • Data processing skills that generate reports or exports
  • Any skill that creates files meant to be accessed later

Example Scenario

# PDF skill script generates a file
# Expected: File automatically becomes available as artifact
# Actual: File is lost after script execution

Activity

  1. added
    tools[Component] This issue is related to tools
    on May 4, 2026
  2. added theissue type on May 4, 2026
  3. self-assigned this
    on May 4, 2026
  4. klateefa commented on May 4, 2026

    @klateefa

    @henrywang0314 Thanks for the update. The request is currently being reviewed, and I will let you know if anything further is needed. Thank you for your understanding.

  5. added
    needs review[Status] The PR/issue is awaiting review from the maintainer
    on May 4, 2026
  6. rohityan commented on Jun 5, 2026

    @rohityan
    Collaborator

    /adk-issue-analyze

  7. adk-bot commented on Jun 5, 2026

    @adk-bot
    Collaborator

    GitHub Issue #5579 Analysis: Support automatic artifact storage for files generated by skill toolset scripts

    Executive Summary

    1. What is broken? When executing agent skill scripts (via RunSkillScriptTool), files generated by the scripts (such as generated PDFs, images, data exports) are deleted immediately because the environment is executed within a nested tempfile.TemporaryDirectory that is discarded upon completion. There is no automatic detection or retention of these files.
    2. Is there a linked PR that fixes this issue? None.
    3. Recommendation: Should Fix (Medium Priority) — Standardizing dynamic output capture from skill script tools dramatically improves the usability of document, spreadsheet, and multimodal asset-generation skills without forcing developers to implement complex, custom storage workarounds.
    Detailed Analysis

    1. Root Cause Analysis ("What is broken?")

    When an agent invokes a skill script via the RunSkillScriptTool.run_async method, it utilizes an internal helper class _SkillScriptCodeExecutor to serialize and execute the workspace script using the underlying code executor (e.g., local, container, or VM-based sandbox).

    The execution flow decomposes as follows:

    • _build_wrapper_code designs a self-contained Python wrapper script.
    • The wrapper instantiates a temporary directory, switches the active working directory, and materializes skill assets locally:
      def _materialize_and_run():
        _orig_cwd = os.getcwd()
        with tempfile.TemporaryDirectory() as td:
          for rel_path, content in _files.items():
            ...
          os.chdir(td)
          try:
            # runs python with runpy or shell with subprocess.run()
    • Any files created during execution of the skill's Python code or shell scripts are saved locally inside td.
    • Once the script finishes or exits, the with tempfile.TemporaryDirectory() as td: context block is exited. This recursively wipes the temporary directory, purging all newly written documents, reports, or visual assets before they can be captured.

    2. Existing Pull Requests ("Is there a linked PR that fixes this issue?")

    • Linked PR: None
    • PR URL: N/A
    • Analysis: A thorough investigation across existing pull requests mentioning issue 5579 or containing relevant keywords ("artifact extraction", "skill outputs") confirms no corresponding PR or branch has been submitted to resolve this issue yet.

    3. Recommendation

    • Recommendation: Should Fix (Medium Priority)
    • Rationale:
      • Developer Experience: Generating data tables, charts, and reports is a first-class agent use case. Supporting automatic or opt-in file retention significantly saves developer lift.
      • Proposed Solution:
        1. Update _build_wrapper_code to perform a walk/diff of td after tool execution.
        2. Detect any newly created or modified files that are not part of the initial skill resource dictionary (_files).
        3. Encode these files as base64-serialized data within the JSON result envelope printed to standard output.
        4. Pass the tool_context to execute_script_async, allowing it to call await tool_context.save_artifact(...) to persist the discovered files in the ArtifactService automatically.
        5. Return the list of saved artifact filenames back to the agent in the tool result dictionary, e.g. "saved_artifacts": ["output_report.pdf"].
      • Complexity: Low to Medium. Minimal risk of side-effects since it operates completely inside the closed sandbox execution wrapper block.
  8. a2105z commented on Aug 11, 2026

    @a2105z
    Contributor

    I'd like to take this — implementing automatic artifact capture for files generated by skill scripts (walk/diff the script tempdir after execution, save_artifact via tool_context, return saved_artifacts in the tool result).

    Following the bot analysis path in _build_wrapper_code / RunSkillScriptTool. Will open a PR shortly.

  9. a2105z commented on Aug 11, 2026

    @a2105z
    Contributor

    Opened a fix in #6675

    Implementation follows the bot analysis: walk/diff the script tempdir after execution, persist new files via tool_context.save_artifact, and return saved_artifacts in the tool result.

    cc @klateefa @GWeale @DeanChensj

  10. added a commit that references this issue on Aug 17, 2026
    140e5fa
  11. added a commit that references this issue on Oct 2, 2026
    beaef0d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

needs review[Status] The PR/issue is awaiting review from the maintainertools[Component] This issue is related to tools

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions