Skip to content

Commit

Permalink
update intervention docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Oct 6, 2024
1 parent 9c09438 commit e342779
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions examples/intervention/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,51 +68,42 @@ If you have a static prompt you want to use, or a dataset of these, you could pu

### Agent Loop

The agent loop is [just a plain Inspect solver.](https://inspect.ai-safety-institute.org.uk/solvers.html). It runs a generation and appends the output to the messages list in `TaskState`. Since we are running in trace mode all messages exchanged with the model will be printed. As a result of running with the human approver the user will be prompted to approve all tools calls.
The agent loop is [just a plain Inspect solver.](https://inspect.ai-safety-institute.org.uk/solvers.html). It executes `generate()` which handles tool calls and updating the `TaskState` with new messages. Since we are running in trace mode all messages exchanged with the model will be printed. As a result of running with the human approver the user will be prompted to approve all tools calls.

``` python

@solver
def agent_loop(tools: list[Tool]) -> Solver:
async def solve(state: TaskState, generate: Generate) -> TaskState:
# get the active model
model = get_model()
# set tools
state.tools = tools

# main loop
while not state.completed:
# generate
output = await model.generate(state.messages, tools)
state.output = output
state.messages.append(output.message)

# call tools
if output.message.tool_calls:
tool_output = await call_tools(output.message, tools)
state.messages.extend(tool_output)

# no tool calls, see what the user wants to do
else:
next_action = ask_for_next_action()
with input_screen():
match next_action.strip().lower():
case "exit":
break
case "":
state.messages.append(
ChatMessageUser(
content="Please continue working on this task."
)
# generate w/ tool calls, approvals, etc.
state = await generate(state)

# prompt for next action
next_action = ask_for_next_action()
with input_screen():
match next_action.strip().lower():
case "exit":
break
case "":
state.messages.append(
ChatMessageUser(
content="Please continue working on this task."
)
continue
case _:
state.messages.append(ChatMessageUser(content=next_action))
)
continue
case _:
state.messages.append(ChatMessageUser(content=next_action))

return state

return solve
```

If there are no tool calls, the user will get a choice to terminate the conversation, force another generation, or send a custom user message to the model.
Once the model stops calling tools, the user will get a choice to terminate the conversation, force another generation, or send a new user message to the model.

## Sandboxing

Expand Down

0 comments on commit e342779

Please sign in to comment.