-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
117 lines (110 loc) · 4.22 KB
/
action.yml
File metadata and controls
117 lines (110 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: 'OpenHands AI Action'
description: 'Run OpenHands with human readable customizable prompts and environment variables.'
author: 'Zainan Victor Zhou <zzn+openhands-action@zzn.im>'
branding:
icon: 'activity'
color: 'purple'
inputs:
prompt:
description: 'The natural language prompt or task to execute with OpenHands AI'
required: true
llm_model:
description: 'The LLM model to use for task execution'
required: false
default: 'anthropic/claude-3-7-sonnet-20250219'
llm_api_key:
description: 'API key for the LLM service (e.g., Anthropic API key)'
required: true
log_all_events:
description: 'Enable detailed logging of all events during task execution'
required: false
default: 'true'
runtime_image:
description: 'Docker image for the runtime environment'
required: false
default: 'docker.all-hands.dev/all-hands-ai/runtime:0.32-nikolaik'
openhands_image:
description: 'Docker image for the OpenHands AI service'
required: false
default: 'docker.all-hands.dev/all-hands-ai/openhands:0.32'
additional_env:
description: |
JSON string of additional environment variables to pass to the container.
Example:
{
"CUSTOM_VAR": "value",
"ANOTHER_VAR": "another_value"
}
These will be available in the container as environment variables.
required: false
default: '{}'
cli_args:
description: 'Additional CLI arguments to pass to the OpenHands agent'
required: false
default: ''
github_token:
description: 'GitHub token for API access (will be passed as GITHUB_TOKEN env var)'
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Set up Docker
uses: docker/setup-buildx-action@v2
- name: Validate LLM API Key
shell: bash
run: |
if [ -z "${{ inputs.llm_api_key }}" ]; then
echo "::error::LLM_API_KEY is required but not provided"
exit 1
fi
- name: Run OpenHands
id: openhands
shell: bash
env:
WORKSPACE_BASE: ${{ github.workspace }}
LLM_MODEL: ${{ inputs.llm_model }}
LLM_API_KEY: ${{ inputs.llm_api_key }}
LOG_ALL_EVENTS: ${{ inputs.log_all_events }}
ADDITIONAL_ENV: ${{ inputs.additional_env }}
PROMPT: ${{ inputs.prompt }}
CLI_ARGS: ${{ inputs.cli_args }}
GITHUB_TOKEN: ${{ inputs.github_token }}
run: |
# Parse additional environment variables from JSON
if [ "$ADDITIONAL_ENV" != "{}" ]; then
echo "Processing additional environment variables..."
EXTRA_ENV_ARGS=$(echo "$ADDITIONAL_ENV" | jq -r 'to_entries | map("-e " + .key + "=" + .value) | join(" ")')
echo "Additional environment variables: $EXTRA_ENV_ARGS"
else
EXTRA_ENV_ARGS=""
echo "No additional environment variables provided"
fi
# Add GITHUB_TOKEN to EXTRA_ENV_ARGS if provided
if [ ! -z "$GITHUB_TOKEN" ]; then
EXTRA_ENV_ARGS="$EXTRA_ENV_ARGS -e GITHUB_TOKEN=$GITHUB_TOKEN"
echo "GITHUB_TOKEN will be passed to the container."
else
echo "GITHUB_TOKEN was not provided or is empty, not adding to EXTRA_ENV_ARGS."
fi
# Run Docker command with all environment variables
echo "Final EXTRA_ENV_ARGS (including GITHUB_TOKEN if set): $EXTRA_ENV_ARGS"
echo "Running OpenHands with the following environment variables:"
echo "- LLM_MODEL: $LLM_MODEL"
echo "- LOG_ALL_EVENTS: $LOG_ALL_EVENTS"
echo "- Prompt: $PROMPT"
echo "- CLI Arguments: $CLI_ARGS"
# Execute the task
docker run -i \
--pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=${{ inputs.runtime_image }} \
-e WORKSPACE_MOUNT_PATH=$WORKSPACE_BASE \
-e LLM_API_KEY=$LLM_API_KEY \
-e LLM_MODEL=$LLM_MODEL \
-e LOG_ALL_EVENTS=$LOG_ALL_EVENTS \
$EXTRA_ENV_ARGS \
-v $WORKSPACE_BASE:/opt/workspace_base \
-v /var/run/docker.sock:/var/run/docker.sock \
--add-host host.docker.internal:host-gateway \
${{ inputs.openhands_image }} \
python -m openhands.core.main -t "Run export GITHUB_TOKEN=$GITHUB_TOKEN and then ${PROMPT}" $CLI_ARGS