Skip to content

Commit a15d7ef

Browse files
committed
new: default task override with new --task argument
1 parent 31c3b61 commit a15d7ef

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

docs/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ This will download, extract and install the agent to the folder `$HOME/.nerve/ag
6666
nerve run changelog
6767
```
6868

69+
You can override the default task of any agent:
70+
71+
```bash
72+
nerve run changelog --task 'use a single sentence for the changelog'
73+
```
74+
6975
You can uninstall agents with:
7076

7177
```bash

nerve/cli/run.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def run(
3737
pathlib.Path,
3838
typer.Argument(help="Agent or workflow to execute"),
3939
] = pathlib.Path("."),
40+
task: t.Annotated[
41+
str | None,
42+
typer.Option("--task", "-t", help="Set or override the task for the agent."),
43+
] = None,
4044
generator: t.Annotated[
4145
str,
4246
typer.Option("--generator", "-g", help="If the agent generator field is not set, use this generator."),
@@ -70,7 +74,7 @@ def run(
7074
] = DEFAULT_MAX_COST,
7175
timeout: t.Annotated[
7276
int | None,
73-
typer.Option("--timeout", "-t", help="Timeout in seconds"),
77+
typer.Option("--timeout", help="Timeout in seconds"),
7478
] = DEFAULT_TIMEOUT,
7579
log_path: t.Annotated[
7680
pathlib.Path | None,
@@ -90,6 +94,7 @@ def run(
9094
generator,
9195
# convert the conversation strategy string to a valid enum
9296
conversation.strategy_from_string(conversation_strategy),
97+
task,
9398
ctx.args,
9499
max_steps,
95100
max_cost,
@@ -134,6 +139,7 @@ async def _run(
134139
input_path: pathlib.Path,
135140
generator: str,
136141
conv_window_strategy: WindowStrategy,
142+
task_override: str | None,
137143
start_state_args: list[str],
138144
max_steps: int = 100,
139145
max_cost: float = 10.0,
@@ -180,4 +186,4 @@ async def _run(
180186
logger.error(f"path '{input_path}' is not a valid workflow or agent configuration")
181187
raise typer.Abort()
182188

183-
await flow.run()
189+
await flow.run(task_override)

nerve/runtime/flow.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,17 @@ async def from_path(
9696
timeout=timeout,
9797
)
9898

99-
async def _setup_if_needed(self) -> None:
99+
async def _setup_if_needed(self, task_override: str | None = None) -> None:
100100
if self.started_at is None:
101101
self.started_at = time.time()
102102

103103
if self.curr_actor is None:
104104
self.curr_actor = self.actors[self.curr_actor_idx]
105105

106+
if task_override:
107+
logger.info(f"🎯 setting task: {task_override}")
108+
self.curr_actor.configuration.task = task_override
109+
106110
state.set_tools({tool.__name__: tool for tool in self.curr_actor.runtime.tools})
107111
state.set_defaults(self.curr_actor.configuration.defaults)
108112
state.on_task_started(self.curr_actor)
@@ -150,7 +154,7 @@ def done(self) -> bool:
150154

151155
return False
152156

153-
async def run(self) -> None:
157+
async def run(self, task_override: str | None = None) -> None:
154158
state.on_event(
155159
"flow_started",
156160
{
@@ -160,7 +164,7 @@ async def run(self) -> None:
160164
)
161165

162166
while not self.done():
163-
await self._setup_if_needed()
167+
await self._setup_if_needed(task_override)
164168
if self.curr_actor:
165169
await self.shell.interact_if_needed(self.curr_actor)
166170
await self.step()

0 commit comments

Comments
 (0)