Using Artifact File Directory in Tool Development

Method 1: Using Relative Paths (Recommended)

Using relative paths is the simplest method, as they are automatically resolved to point to the artifact file directory.
def run_tool(config, args):
    #  Relative paths automatically go to /workspace
    output_file = "output.csv"
    
    with open(output_file, "w") as f:
        f.write("data\n")
    
    # File is at /workspace/output.csv
    return f"Created {output_file}"

Method 2: Using Environment Variable

Alternatively, the artifact file directory can be obtained directly from the designated environment variable.
import os

def run_tool(config, args):
    # Get artifact file directory from environment variable
    artifact_dir = os.environ.get('SESSION_DIRECTORY', '/workspace')
    
    # Construct full path
    output_file = os.path.join(artifact_dir, "output.csv")
    
    with open(output_file, "w") as f:
        f.write("data\n")
    
    return f"Created {output_file}"