If there's a high chance that your model will call tool X, don't waste token round trips telling the model to fetch it, that is, instead of a pseudo-prompt like:
When looking at deployments, you will likely want to fetch the list of published git tags,
so you can use it to deploy to prod.
Here's what happened so far:
{{ thread.events }}
What's the next step?
Answer in JSON format with one of the following intents:
{
intent: 'deploy_backend_to_prod',
tag: string
} OR {
intent: 'list_git_tags'
} OR {
intent: 'done_for_now',
message: string
}and your code looks like
thread = {"events": [initial_message]}
next_step = await determine_next_step(thread)
while True:
switch next_step.intent:
case 'list_git_tags':
tags = await fetch_git_tags()
thread["events"].append({
type: 'list_git_tags',
data: tags,
})
case 'deploy_backend_to_prod':
deploy_result = await deploy_backend_to_prod(next_step.data.tag)
thread["events"].append({
"type": 'deploy_backend_to_prod',
"data": deploy_result,
})
case 'done_for_now':
await notify_human(next_step.message)
break
# ...You might as well just fetch the tags and include them in the context window, like:
- When looking at deployments, you will likely want to fetch the list of published git tags,
- so you can use it to deploy to prod.
+ The current git tags are:
+ {{ git_tags }}
Here's what happened so far:
{{ thread.events }}
What's the next step?
Answer in JSON format with one of the following intents:
{
intent: 'deploy_backend_to_prod',
tag: string
- } OR {
- intent: 'list_git_tags'
} OR {
intent: 'done_for_now',
message: string
}
and your code looks like
thread = {"events": [initial_message]}
+ git_tags = await fetch_git_tags()
- next_step = await determine_next_step(thread)
+ next_step = await determine_next_step(thread, git_tags)
while True:
switch next_step.intent:
- case 'list_git_tags':
- tags = await fetch_git_tags()
- thread["events"].append({
- type: 'list_git_tags',
- data: tags,
- })
case 'deploy_backend_to_prod':
deploy_result = await deploy_backend_to_prod(next_step.data.tag)
thread["events"].append({
"type": 'deploy_backend_to_prod',
"data": deploy_result,
})
case 'done_for_now':
await notify_human(next_step.message)
break
# ...or even just include the tags in the thread and remove the specific parameter from your prompt template:
thread = {"events": [initial_message]}
+ # add the request
+ thread["events"].append({
+ "type": 'list_git_tags',
+ })
git_tags = await fetch_git_tags()
+ # add the result
+ thread["events"].append({
+ "type": 'list_git_tags_result',
+ "data": git_tags,
+ })
- next_step = await determine_next_step(thread, git_tags)
+ next_step = await determine_next_step(thread)
while True:
switch next_step.intent:
case 'deploy_backend_to_prod':
deploy_result = await deploy_backend_to_prod(next_step.data.tag)
thread["events"].append(deploy_result)
case 'done_for_now':
await notify_human(next_step.message)
break
# ...Overall:
Again, AI engineering is all about Context Engineering.