pydantic-ai/.github/workflows/shared/engine-zai.md

13 KiB

imports runtimes max-ai-credits models engine jobs post-steps safe-outputs
pydantic/pydantic-ai/src/pydantic_ai_harness/gh-aw/pydantic.md@b11b8984abedc3761d7cc01306aeb3a35f6a33dd
uv
-1
default-ai-credits-pricing providers
input cache_read output
0.15 0.03 0.50
anthropic
models
glm-5.3-flash
cost
input cache_read output
0.00000015 0.00000003 0.00000050
id version env concurrency
pydantic-ai 0.70.0
ANTHROPIC_BASE_URL ANTHROPIC_API_KEY PAI_AGENT PAI_RESULT_METADATA PAI_OTEL_EXPORT_PATH LOGFIRE_SERVICE_VERSION PYTHONPATH XDG_CONFIG_HOME GITHUB_WORKFLOW PYDANTIC_AI_TRIGGER_EVENT PYDANTIC_AI_RUN_ATTEMPT PYDANTIC_AI_TASK_ID GH_AW_HARNESS_MAX_RETRIES
https://api.z.ai/api/anthropic ${{ steps.agent_start_health.outputs.account == 'backup' && secrets.ZAI_BACKUP_API_KEY || secrets.ZAI_API_KEY }} pydantic_ai_gh_aw_shim.agent:agent pydantic_ai_gh_aw_shim.agent:result_metadata /tmp/gh-aw/pydantic-ai-private-otel.jsonl ${{ steps.workflow-policy.outputs.service-version }} /tmp/gh-aw/workflow-python /tmp/gh-aw/clai2-config ${{ github.workflow }} ${{ github.event_name }} ${{ github.run_attempt }} ${{ github.workflow }}:${{ github.event_name }}:${{ github.event.pull_request.number || github.event.issue.number || github.event.workflow_run.head_branch || github.ref_name }}:${{ github.event.pull_request.head.sha || github.event.workflow_run.head_sha || github.sha }}:${{ github.event.comment.id || github.event.issue.id || (github.event_name == 'workflow_dispatch' && github.run_id) || '' }} 0
group queue
gh-aw-pydantic-ai-${{ github.workflow }} max
agent detection
timeout-minutes
360
timeout-minutes
20
name if continue-on-error uses env with
Forward private workflow spans from the host always() true actions/github-script@3a2844b7e9
NODE_USE_ENV_PROXY
1
script
const fs = require('fs'); const path = require('path'); const { parseOTLPEndpoints, parseOTLPHeaders } = require(path.join(process.env.RUNNER_TEMP, 'gh-aw', 'actions', 'send_otlp_span.cjs')); // Diagnostic input only. It cannot supply health decisions or canonical usage. // Keep content-bearing spans out of otel.jsonl and uploaded agent artifacts. const source = '/tmp/gh-aw/pydantic-ai-private-otel.jsonl'; if (!fs.existsSync(source)) return; const descriptor = fs.openSync(source, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK); try { if (!fs.fstatSync(descriptor).isFile()) throw new Error('Workflow telemetry must be a regular file'); const endpoints = parseOTLPEndpoints(); for (const line of fs.readFileSync(descriptor, 'utf8').split('\n').filter(Boolean)) { let payload; try { payload = JSON.parse(line); } catch { throw new Error('Invalid workflow span payload'); } if (!payload || !Array.isArray(payload.resourceSpans)) throw new Error('Invalid workflow span payload'); // Preserve SDK-scrubbed private attributes, including long JSON values. // gh-aw's infrastructure sender truncates strings and mirrors by default. await Promise.all(endpoints.map(async endpoint => { let delivered = false; for (let attempt = 0; attempt < 3; attempt++) { if (attempt) await new Promise(resolve => setTimeout(resolve, 100 * 2 ** (attempt - 1))); try { const response = await fetch(endpoint.url.replace(//$/, '') + '/v1/traces', { method: 'POST', headers: { 'Content-Type': 'application/json', ...parseOTLPHeaders(endpoint.headers || '') }, body: line, signal: AbortSignal.timeout(120000), }); if (response.ok) { delivered = true; break; } if (response.status === 401 || response.status === 403) break; } catch { // Report the outcome without logging private payloads or credentials. } } if (!delivered) core.warning('Private workflow telemetry export failed for a configured collector'); })); } } finally { fs.closeSync(descriptor); fs.unlinkSync(source); }
threat-detection
engine post-steps
false
name id if continue-on-error uses with
Check out the OpenCode threat detector detector_checkout always() && steps.detection_guard.outputs.run_detection == 'true' true actions/checkout@3d3c42e5aa
ref path sparse-checkout persist-credentials
${{ github.workflow_sha }} .gh-aw-detector .github/actions/setup-douwebot-tools .github/scripts false
name id if continue-on-error uses env
Set up OpenCode detector_tools always() && steps.detector_checkout.outcome == 'success' true ./.gh-aw-detector/.github/actions/setup-douwebot-tools
NPM_CONFIG_MIN_RELEASE_AGE
3
name id if continue-on-error timeout-minutes env run
Run OpenCode threat detection detection_agentic_execution always() && steps.detection_setup.outputs.ready == 'true' && steps.threat_detect_install.outcome == 'success' && steps.detector_tools.outcome == 'success' true 15
OPENCODE_API_KEY ZAI_API_KEY ZAI_BACKUP_API_KEY PYTHONPATH GH_AW_HARNESS_MAX_RETRIES
${{ secrets.OPENCODE_API_KEY }} ${{ secrets.ZAI_API_KEY }} ${{ secrets.ZAI_BACKUP_API_KEY }} ${{ runner.temp }}/douwebot-tools/python 3
export PATH="$RUNNER_TEMP/douwebot-tools/bin:$RUNNER_TEMP/douwebot-tools/opencode/node_modules/.bin:$PATH" python3 .gh-aw-detector/.github/scripts/gh_aw_opencode_detect.py
name if continue-on-error uses env with
Report detector usage and outcome always() && steps.detection_guard.outputs.run_detection == 'true' true actions/github-script@3a2844b7e9
DETECTOR_OUTCOME DETECTOR_JOB_STATUS DETECTOR_PROVIDER DETECTOR_PLAN OTEL_SERVICE_NAME
${{ steps.detection_agentic_execution.outcome }} ${{ job.status }} ${{ steps.detection_agentic_execution.outputs.provider }} ${{ steps.detection_agentic_execution.outputs.plan }} gh-aw.threat-detection
script
const fs = require('fs'); const path = require('path'); const { logSpan } = require(path.join(process.env.RUNNER_TEMP, 'gh-aw', 'actions', 'otlp.cjs')); const directory = '/tmp/gh-aw/threat-detection'; const read = name => fs.existsSync(name) ? fs.readFileSync(name, 'utf8') : ''; const log = read(path.join(directory, 'detection.log')); // One stream per OpenCode attempt. Read only step counters: the streams' text is model-authored. const streams = fs.readdirSync(process.env.RUNNER_TEMP).filter(name => /^gh-aw-opencode-detector-\d+.ndjson$/.test(name)); // A killed run can leave an unterminated last line; every complete event ends in a newline. const steps = streams.flatMap(name => read(path.join(process.env.RUNNER_TEMP, name)).split('\n').slice(0, -1)) .filter(line => line.includes('"step_finish"')).map(line => JSON.parse(line)) .filter(event => event.type === 'step_finish').map(event => event.part); const marker = log.match(/THREAT_DETECTION_STATUS: reason=(\w+) exit=(\d+)/); const verdictText = read(path.join(directory, 'detection_result.json')); const verdict = verdictText ? JSON.parse(verdictText) : null; const outcome = process.env.DETECTOR_JOB_STATUS === 'cancelled' ? 'cancelled' : process.env.DETECTOR_OUTCOME || 'unknown'; const valid = verdict && ['prompt_injection', 'secret_leak', 'malicious_patch'].every(key => typeof verdict[key] === 'boolean'); const failed = outcome !== 'success' || !valid; const sum = value => steps.reduce((total, step) => total + value(step), 0); const attributes = { 'gh-aw.telemetry.source': 'detector-evidence', 'gh-aw.detector.outcome': outcome, 'gh-aw.detector.reason': marker ? marker[1] : valid ? 'verdict' : 'missing_verdict', 'gh-aw.detector.verdict': valid ? verdict.prompt_injection || verdict.secret_leak || verdict.malicious_patch ? 'blocked' : 'clean' : 'missing', 'gh-aw.detector.provider': process.env.DETECTOR_PROVIDER || 'unknown', 'gh-aw.detector.plan': process.env.DETECTOR_PLAN || 'unknown', 'gh-aw.detector.attempts': streams.length, 'gh-aw.detector.requests': steps.length, 'gh-aw.detector.usage_available': steps.length > 0, 'gh-aw.detector.usage.input_tokens': sum(step => step.tokens?.input ?? 0), 'gh-aw.detector.usage.output_tokens': sum(step => step.tokens?.output ?? 0), 'gh-aw.detector.usage.reasoning_tokens': sum(step => step.tokens?.reasoning ?? 0), 'gh-aw.detector.usage.cache_read_tokens': sum(step => step.tokens?.cache?.read ?? 0), 'gh-aw.detector.usage.cache_write_tokens': sum(step => step.tokens?.cache?.write ?? 0), 'gh-aw.detector.cost': sum(step => step.cost ?? 0), 'gh-aw.detector.log_available': Boolean(log), }; await logSpan('gh-aw.detector.result', attributes, { startMs: Number(process.env.GITHUB_AW_OTEL_JOB_START_MS) || Date.now(), isError: failed, errorMessage: failed ? attributes['gh-aw.detector.reason'] : undefined, });