Asynchronous Tool Calls and Mid-Task Steering for Long-Running AI Tasks
Long-running AI tasks need more than longer responses. They require explicit task state, asynchronous tool execution, mid-task corrections, cancellation rules, and protection against stale results. This article explains how to implement these controls, adjust reasoning effort without unnecessarily disrupting prefix caching, and use testable writing constraints to keep outputs grounded. It also provides regression checks for concurrency, steering, stale writes, caching, and output quality.
Long-running tasks are not simply single-turn conversations stretched over time. They involve repeated decisions in uncertain environments: inspecting a project structure, editing files, checking logs, and choosing the next step based on the results.
These tasks often fail not because the model lacks intelligence, but because the control plane is still designed for short exchanges. Generation must wait for tools to finish. Users cannot correct the direction until the response ends. Reasoning effort stays fixed throughout the task. Writing requirements lack verifiable constraints.
The following sections separate these capabilities and describe implementation approaches that do not depend on a particular model product.
1. Separate Three Layers of Control
The statement “users can change instructions mid-task” can describe three very different capabilities.
Application orchestration. The client queues a new instruction or sends it after the current turn finishes. The server does not necessarily retain generated text as unfinished work, so developers must reconstruct the context themselves.
Conversation state. The server recognizes that the current turn is still open. New instructions become part of that turn, while completed tool results and usable portions of the draft remain valid instead of being discarded.
Model behavior. While waiting for external tools, the model can continue planning, drafting, or initiating independent actions rather than being blocked by a protocol that requires a single tool return before proceeding.
Interface features described as “interrupting” or “queuing” often cover only the first layer. Recoverable long-running tasks require the other two layers to exist explicitly in the protocol and state machine. Prompts alone cannot simulate them reliably.
2. Synchronous vs. Asynchronous Tool Calls
Standard tool use is typically synchronous within a turn: the model issues a call, generation pauses, the application executes the tool, and the result is returned before the model continues.
The application may call several APIs in parallel internally. That is host-level parallelism, however, not the model continuing useful work while results are pending.
Synchronous execution works well for short, tightly dependent steps whose results must be consumed immediately—for example, fetching a configuration before selecting a branch. Its costs are also clear:
- A slow tool blocks generation, leaving the user without incremental progress.
- Independent read-only queries become a serial chain, with elapsed time approaching the sum of their durations.
- Retries and timeouts become entangled with whether the model still needs the result, making cancellation semantics unclear.
Asynchronous tool use separates starting a call from consuming its result. Before a result arrives, the model can work on tasks that do not depend on it: organizing existing evidence, drafting sections that do not require the pending data, or starting another independent read-only query. When the result arrives, it is merged into the same task state.
This is a scheduling capability, not merely a longer network timeout.
Good candidates for asynchronous execution include code search, log sampling, document retrieval, and time-consuming static checks. Writes are less suitable when their success or failure must be known immediately to prevent invalid state—for example, overwriting a configuration, committing changes, or deleting resources. These operations should retain synchronous confirmation, or at least use idempotency keys and human confirmation checkpoints.
An illustrative host-side state structure might look like this. It is not a fixed interface from any cloud provider:
task_state:pending_calls: [{id, name, args, started_at}]finished_calls: [{id, result | error}]draft: intermediate conclusions that can be retaineduser_overrides: constraints added during the turn
Merge rules must be deterministic rather than left to the model’s discretion:
- An arriving result updates only its corresponding call ID.
- Conflicting last-write-wins updates must leave an audit trail.
- A timeout is recorded as a failure, not treated as a successful empty result.
3. Mid-Task Steering Without Losing Completed Work
Mid-task steering occurs when a user introduces a more specific goal, rejects an assumption, or narrows the scope while a response is still being generated or tools are still running.
The important question is not whether the interface accepts another message. It is how the server incorporates that message.
Reliable handling requires at least four capabilities.
Preserve completed evidence
Directory summaries already collected and read-only checks already completed should not disappear because the user adds an instruction. Otherwise, the model repeats calls, increasing latency and the risk of inconsistent conclusions.
Distinguish corrections from new tasks
A correction constrains the current turn—for example, “Do not change public interfaces; add tests only.” A new task introduces a separate objective.
If the protocol does not distinguish them, queued plans for the old objective become mixed with the new one.
Prune unexecuted plans
Suppose the model has announced plans to change three areas, and the user rules out two of them. Calls that have not started should be invalidated. Calls already in flight need a cancellation policy or an explicit policy for ignoring their results.
Ignoring a result must be recorded explicitly so that stale output cannot silently re-enter task state.
Provide visible incremental updates
After steering, the system should continue producing updates rather than silently rerunning the entire task. Those updates should identify which new constraint was adopted and which previous plan was abandoned, making the change easy to verify.
Application-level queues remain useful because they keep users from waiting to submit instructions. They do not replace within-turn state.
A common queue-only failure is that the old turn eventually finishes and applies changes the user has already rejected. Use turn version numbers to prevent this: every steering instruction increments the version, and writes from outdated turns are rejected.
4. Adjust Reasoning Effort While Preserving Caching
Task difficulty changes during a long conversation. A quick directory scan may need low reasoning effort, while diagnosing a concurrency defect or designing migration steps may require high effort.
If effort can only be selected at the beginning of a session, the system either spends too much throughout the task or lacks sufficient effort at critical steps.
The difficult part of switching effort is preserving caching. Inference services commonly cache previously computed context prefixes. Rewriting system instructions, rearranging history, or inserting large amounts of unrelated text can invalidate those prefixes, increasing both cost and latency.
Practical guidance:
- Keep stable content at the front: role, safety boundaries, output format, and immutable project constraints.
- Place changing content later: the current step’s objective, effort instructions, newly arrived tool results, and the user’s latest correction.
- Express effort changes as short appended instructions: do not replace the entire system prompt.
- Attach historical tool results through references or summaries: avoid repeatedly pasting their full contents into a new prefix.
Use a few coarse effort levels, such as low, medium, and high. These can correspond to exploring fewer alternatives, considering a normal range of alternatives, or explicitly stating assumptions before acting. Avoid finely graduated numerical levels that cannot be reproduced consistently.
Log the selected level, the reason for the change, and the version number. This helps explain why behavior or style changed during the same conversation.
Low effort suits classification, extraction, file listing, and template completion. High effort suits root-cause analysis, interface compatibility decisions, and designs that require challenging an initial assumption.
Start with low effort by default, increasing it when evidence is insufficient or the user requests deeper analysis. Not every step needs an extended explanation of the reasoning process.
5. Use Testable Prompt Constraints to Reduce Drift and Generic Writing
Drift prevention, instruction following, personalization, and writing quality address a different class of failure: the tools work, but the response goes off course or reads like interchangeable marketing copy.
Prevent drift
In long contexts, a model may lose track of early hard constraints or follow instructions embedded in tool output.
Keep hard constraints short, testable, and in the stable prefix. Append only three to five success criteria for the current turn. Treat tool output as data, not instructions; where necessary, remove imperative instructions before storing it.
When drift occurs, use mid-task steering to identify the specific violated constraint rather than asking vaguely for a “more professional rewrite.”
Prioritize verifiable instructions
Acceptance criteria are more useful than requests for eloquence. For example:
- “Give the conclusion first, then the evidence. Each piece of evidence must reference a returned tool result ID.”
- “If something is uncertain, label it unknown. Do not invent interface names.”
Unobservable requirements such as “be more insightful” are difficult to evaluate.
Make personalization stable
Personalization should represent consistent preferences, not a new persona on every turn: the intended audience, the desired level of code detail, phrases to avoid, and terminology conventions.
Place these preferences in the stable prefix. Repeatedly rewriting a personality description disrupts caching and encourages stylistic drift.
Make writing verifiable
Generic technical writing often lacks a clear subject, trade-offs, or failure conditions, relying instead on slogans such as “empower,” “close the loop,” or “transform.”
Prompts can prohibit subjectless slogans, require each judgment to include a counterexample or boundary condition, and constrain paragraph roles: one sentence of background, one paragraph on the mechanism, one on trade-offs, and one on verification.
The goal is not more elaborate prose. It is writing that lets readers check the claims by following the stated steps.
None of these prompt improvements replaces protocol capabilities. Without asynchronous calls and mid-turn state, even a strong prompt remains trapped in a cycle of waiting and restarting.
6. Make Dependencies and Cancellation Explicit
Separate tools into read-only operations and writes.
Read-only operations can generally default to concurrent, asynchronous execution. Writes should default to serial execution, with a brief statement of their impact before they run.
Represent dependencies with explicit fields—for example, “this call depends on the result of call_id.” Do not rely on a natural-language plan such as “do this after the other call returns.”
Cancellation needs three distinct states:
- Not yet dispatched: discard the call.
- Dispatched and cancellable: send a cancellation request and wait for a terminal state.
- Not cancellable: mark the result as invalid; when it returns, it must not update the draft.
If a user steers the task twice in succession, the highest version takes precedence. Drafts from intermediate versions may remain in logs but must not enter the final response.
Keep volatile fields out of cache keys, including timestamps, random request IDs, and full raw tool output. Summaries should also be stable: identical input should produce identical summaries, or prefix caching becomes ineffective.
7. Validate with a Fixed Long-Running Regression Task
Use a repeatable long-running task for regression testing rather than judging the system by feel.
Blocking behavior
Run two independent read-only tools. Elapsed time should approach the duration of the slower tool, not the sum of both durations.
If the times still add up, either the model layer or the host layer is waiting serially.
Mid-task steering
Halfway through a turn, add: “Do not modify production configuration; output a checklist only.”
The final response must not include the rejected modification plan. Completed read-only results should be referenced rather than collected again.
Stale writes
After steering, a simulated write from an older version must be rejected. Logs should show the version mismatch.
Reasoning effort and caching
Switch from low to high effort while retaining the same prefix. Cache invalidation should mainly affect the appended tail, rather than forcing the entire history to be recomputed.
If monitoring shows complete prefix invalidation, changing instructions may have been inserted too early in the context.
Writing quality
Check for unsupported interface names, performance promises without boundary conditions, and slogans that cannot be translated into actions.
If they appear, tighten the “label unknowns as unknown” constraint instead of adding more stylistic adjectives.
8. Where These Capabilities Belong
These are application architecture concerns: state, versioning, cancellation, cache prefixes, and testable prompts.
Compute and storage can run on general-purpose cloud infrastructure using container platforms, message queues, object storage, and logging services:
- Message queues deliver tool results.
- Object storage retains reusable intermediate summaries.
- Logging services record versions and reasoning-effort levels.
For teams already using these general infrastructure categories on Baidu AI Cloud, the same long-running task workflow can be supported by keeping result writes versioned, write operations auditable, and context prefixes stable. The design does not need to be described as a proprietary event type or tied to a particular product interface.
Do not mistake an interface’s interruption feature for model-level asynchronous execution. Do not treat “please think carefully” as a switchable, cache-preserving reasoning setting. And do not rewrite the system prompt on every turn merely to create a personalized style.
Remove unnecessary synchronous waits, stale plans, and empty prose from long-running tasks. What remains is technical collaboration that can recover from interruptions, explain its decisions, and produce useful, readable results.
