Skip to content

Commit a2b8ff5

Browse files
committed
ensure_active_profile
2 parents 34b27de + 6753700 commit a2b8ff5

File tree

7 files changed

+106
-2
lines changed

7 files changed

+106
-2
lines changed

CLI.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ $ dreadnode agent deploy [OPTIONS]
8585

8686
* `-m, --model TEXT`: The inference model to use for this run
8787
* `-d, --dir DIRECTORY`: The agent directory [default: .]
88+
* `-e, --env-var TEXT`: Environment vars to override for this run (key=value)
89+
* `-p, --param TEXT`: Define custom parameters for this run (key = value in toml syntax or @filename.toml for multiple values)
90+
* `-c, --command TEXT`: Override the container command for this run.
8891
* `-s, --strike TEXT`: The strike to use for this run
8992
* `-w, --watch`: Watch the run status [default: True]
9093
* `--help`: Show this message and exit.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ dreadnode agent push
165165
# start a new run using the latest agent version.
166166
dreadnode agent deploy
167167

168+
# start a new run using the latest agent version with custom environment variables
169+
dreadnode agent deploy --env-var TEST_ENV=test --env-var ANOTHER_ENV=another_value
170+
171+
# start a new run using the latest agent version with custom parameters (using toml syntax)
172+
dreadnode agent deploy --param "foo = 'bar'" --param "baz = 123.0"
173+
174+
# start a new run using the latest agent version with custom parameters from a toml file
175+
dreadnode agent deploy --param @parameters.toml
176+
177+
# start a new run using the latest agent version and override the container command
178+
dreadnode agent deploy --command "echo 'Hello, world!'"
179+
168180
# show the latest run of the currently active agent
169181
dreadnode agent latest
170182

dreadnode_cli/agent/cli.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
import typing as t
66

7+
import toml
78
import typer
89
from rich import box, print
910
from rich.live import Live
@@ -328,6 +329,31 @@ def push(
328329
print(":tada: Agent pushed. use [bold]dreadnode agent deploy[/] to start a new run.")
329330

330331

332+
def prepare_run_context(
333+
env_vars: list[str] | None, parameters: list[str] | None, command: str | None
334+
) -> Client.StrikeRunContext | None:
335+
if not env_vars and not parameters and not command:
336+
return None
337+
338+
context = Client.StrikeRunContext()
339+
340+
if env_vars:
341+
context.environment = {env_var.split("=")[0]: env_var.split("=")[1] for env_var in env_vars}
342+
343+
if parameters:
344+
context.parameters = {}
345+
for param in parameters:
346+
if param.startswith("@"):
347+
context.parameters.update(toml.load(open(param[1:])))
348+
else:
349+
context.parameters.update(toml.loads(param))
350+
351+
if command:
352+
context.command = command
353+
354+
return context
355+
356+
331357
@cli.command(help="Start a new run using the latest active agent version")
332358
@pretty_cli
333359
def deploy(
@@ -338,6 +364,22 @@ def deploy(
338364
pathlib.Path,
339365
typer.Option("--dir", "-d", help="The agent directory", file_okay=False, resolve_path=True),
340366
] = pathlib.Path("."),
367+
env_vars: t.Annotated[
368+
list[str] | None,
369+
typer.Option("--env-var", "-e", help="Environment vars to override for this run (key=value)"),
370+
] = None,
371+
parameters: t.Annotated[
372+
list[str] | None,
373+
typer.Option(
374+
"--param",
375+
"-p",
376+
help="Define custom parameters for this run (key = value in toml syntax or @filename.toml for multiple values)",
377+
),
378+
] = None,
379+
command: t.Annotated[
380+
str | None,
381+
typer.Option("--command", "-c", help="Override the container command for this run."),
382+
] = None,
341383
strike: t.Annotated[str | None, typer.Option("--strike", "-s", help="The strike to use for this run")] = None,
342384
watch: t.Annotated[bool, typer.Option("--watch", "-w", help="Watch the run status")] = True,
343385
group: t.Annotated[str | None, typer.Option("--group", "-g", help="Group to associate this run with")] = None,
@@ -357,6 +399,8 @@ def deploy(
357399
if strike is None:
358400
raise Exception("No strike specified, use -s/--strike or set the strike in the agent config")
359401

402+
context = prepare_run_context(env_vars, parameters, command)
403+
360404
user_models = UserModels.read()
361405
user_model: Client.UserModel | None = None
362406

@@ -388,7 +432,7 @@ def deploy(
388432
)
389433

390434
run = client.start_strike_run(
391-
agent.latest_version.id, strike=strike, model=model, user_model=user_model, group=group
435+
agent.latest_version.id, strike=strike, model=model, user_model=user_model, group=group, context=context
392436
)
393437
agent_config.add_run(run.id).write(directory)
394438
formatted = format_run(run, server_url=server_config.url)

dreadnode_cli/agent/format.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,19 @@ def format_run(
295295
table.add_row("start", format_time(run.start))
296296
table.add_row("end", format_time(run.end))
297297

298+
if run.context and (run.context.environment or run.context.parameters or run.context.command):
299+
table.add_row("", "")
300+
if run.context.environment:
301+
table.add_row(
302+
"environment", " ".join(f"[magenta]{k}[/]=[yellow]{v}[/]" for k, v in run.context.environment.items())
303+
)
304+
if run.context.parameters:
305+
table.add_row(
306+
"parameters", " ".join(f"[magenta]{k}[/]=[yellow]{v}[/]" for k, v in run.context.parameters.items())
307+
)
308+
if run.context.command:
309+
table.add_row("command", f"[bold][red]{run.context.command}[/red][/bold]")
310+
298311
components: list[RenderableType] = [
299312
table,
300313
format_zones_verbose(run.zones, include_logs=include_logs) if verbose else format_zones_summary(run.zones),

dreadnode_cli/api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ class StrikeRunZone(_StrikeRunZone):
362362
inferences: list[dict[str, t.Any]]
363363
metrics: dict[str, "Client.StrikeMetric"]
364364

365+
class StrikeRunContext(BaseModel):
366+
environment: dict[str, str] | None = None
367+
parameters: dict[str, t.Any] | None = None
368+
command: str | None = None
369+
365370
class _StrikeRun(BaseModel):
366371
id: UUID
367372
key: str
@@ -376,6 +381,7 @@ class _StrikeRun(BaseModel):
376381
agent_name: str | None = None
377382
agent_revision: int
378383
agent_version: "Client.StrikeAgentVersion"
384+
context: "Client.StrikeRunContext | None" = None
379385
status: "Client.StrikeRunStatus"
380386
start: datetime | None
381387
end: datetime | None
@@ -464,6 +470,7 @@ def start_strike_run(
464470
*,
465471
model: str | None = None,
466472
user_model: UserModel | None = None,
473+
context: StrikeRunContext | None = None,
467474
strike: UUID | str | None = None,
468475
group: UUID | str | None = None,
469476
) -> StrikeRunResponse:
@@ -476,6 +483,7 @@ def start_strike_run(
476483
"user_model": user_model.model_dump(mode="json") if user_model else None,
477484
"strike": str(strike) if strike else None,
478485
"group": str(group) if group else None,
486+
"context": context.model_dump(mode="json") if context else None,
479487
},
480488
)
481489
return self.StrikeRunResponse(**response.json())

poetry.lock

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ httpx = "^0.27.2"
2020
ruamel-yaml = "^0.18.6"
2121
docker = "^7.1.0"
2222
pydantic-yaml = "^1.4.0"
23+
toml = "^0.10.2"
24+
types-toml = "^0.10.8.20240310"
2325

2426
[tool.pytest.ini_options]
2527
asyncio_mode = "auto"

0 commit comments

Comments
 (0)