-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy path16d_credentials_gh_cli.py
More file actions
54 lines (45 loc) · 1.8 KB
/
Copy path16d_credentials_gh_cli.py
File metadata and controls
54 lines (45 loc) · 1.8 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
# Copyright (c) 2025 Agentspan
# Licensed under the MIT License. See LICENSE file in the project root for details.
"""Credentials — GitHub CLI (gh) with automatic credential injection.
Demonstrates:
- cli_allowed_commands=["gh"] gives the agent a run_command tool
- credentials=["GH_TOKEN"] auto-injects the token into the tool env
- The agent calls `gh` commands directly — no subprocess boilerplate needed
Setup (one-time, via CLI):
agentspan login
agentspan credentials set GH_TOKEN <your-gh-token>
Requirements:
- Agentspan server running at AGENTSPAN_SERVER_URL
- AGENTSPAN_LLM_MODEL set (or defaults to openai/gpt-5.4)
- `gh` CLI installed (https://cli.github.com)
- GH_TOKEN stored via `agentspan credentials set`
"""
from conductor.ai.agents import Agent, AgentRuntime
from settings import settings
agent = Agent(
name="github_cli_agent",
model=settings.llm_model,
cli_allowed_commands=["gh"],
credentials=["GH_TOKEN"],
instructions=(
"You are a GitHub assistant that uses the `gh` CLI tool. "
"GH_TOKEN is already set in the environment — gh will use it automatically. "
"Use --json for structured output when listing repos, issues, or PRs. "
"Always confirm with the user before creating issues or PRs."
),
)
if __name__ == "__main__":
with AgentRuntime() as runtime:
result = runtime.run(
agent,
"List the 5 most recently updated repos for the 'agentspan'",
)
result.print_result()
# Production pattern:
# 1. Deploy once during CI/CD:
# runtime.deploy(agent)
# CLI alternative:
# agentspan deploy --package examples.16d_credentials_gh_cli
#
# 2. In a separate long-lived worker process:
# runtime.serve(agent)