Using Artifact File Directory in tool development
You can use one of the following methods to xxx:
- Method 1: Using Relative Paths (Recommended).
Use automatic relative path resolution to the Artifact File Directory by using the following script:
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 VariableAlternatively, obtain the Artifact File Directory directly from the designated environment variable by using the following code:
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}"
