Class TakeLeaseAdvisor
java.lang.Object
ai.badmonkey.agentspaces.springai.worker.TakeLeaseAdvisor
- All Implemented Interfaces:
org.springframework.ai.chat.client.advisor.api.Advisor, org.springframework.ai.chat.client.advisor.api.CallAdvisor, org.springframework.ai.chat.client.advisor.api.StreamAdvisor, org.springframework.core.Ordered
public class TakeLeaseAdvisor
extends Object
implements org.springframework.ai.chat.client.advisor.api.CallAdvisor, org.springframework.ai.chat.client.advisor.api.StreamAdvisor
Renews the in-flight take lease on every model round-trip. Ordered after
Spring AI's
ToolCallingAdvisor, it runs inside the tool loop, once per
round-trip; a streamed round-trip also renews on an interval while it runs. A
worker making progress keeps its claim however long its agentic loop takes;
a worker that crashes or hangs stops renewing, and its task reappears one
lease later. Leases can therefore be short, which makes recovery fast.
The advisor does nothing when no take is in flight, so it is safe on every
ChatClient; the auto-configuration adds it to all of them.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intInside the tool loop: afterToolCallingAdvisor.Fields inherited from interface org.springframework.ai.chat.client.advisor.api.Advisor
DEFAULT_CHAT_MEMORY_PRECEDENCE_ORDERFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionTakeLeaseAdvisor(org.springframework.scheduling.TaskScheduler scheduler, Duration streamRenewInterval) Creates the advisor over the worker loop's thread-bound take.TakeLeaseAdvisor(org.springframework.scheduling.TaskScheduler scheduler, Duration streamRenewInterval, Supplier<Optional<ai.badmonkey.agentspaces.agent.TakeContext>> current) Creates the advisor over a supplied take, for tests and custom hosts. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.ai.chat.client.ChatClientResponseadviseCall(org.springframework.ai.chat.client.ChatClientRequest request, org.springframework.ai.chat.client.advisor.api.CallAdvisorChain chain) reactor.core.publisher.Flux<org.springframework.ai.chat.client.ChatClientResponse> adviseStream(org.springframework.ai.chat.client.ChatClientRequest request, org.springframework.ai.chat.client.advisor.api.StreamAdvisorChain chain) getName()intgetOrder()
-
Field Details
-
ORDER
public static final int ORDERInside the tool loop: afterToolCallingAdvisor.- See Also:
-
-
Constructor Details
-
TakeLeaseAdvisor
public TakeLeaseAdvisor(org.springframework.scheduling.TaskScheduler scheduler, Duration streamRenewInterval) Creates the advisor over the worker loop's thread-bound take.- Parameters:
scheduler- the scheduler stream renewals run onstreamRenewInterval- the renewal interval while a stream runs
-
TakeLeaseAdvisor
public TakeLeaseAdvisor(org.springframework.scheduling.TaskScheduler scheduler, Duration streamRenewInterval, Supplier<Optional<ai.badmonkey.agentspaces.agent.TakeContext>> current) Creates the advisor over a supplied take, for tests and custom hosts.- Parameters:
scheduler- the scheduler stream renewals run onstreamRenewInterval- the renewal interval while a stream runscurrent- supplies the take in flight, if any
-
-
Method Details
-
getName
- Specified by:
getNamein interfaceorg.springframework.ai.chat.client.advisor.api.Advisor
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered
-
adviseCall
public org.springframework.ai.chat.client.ChatClientResponse adviseCall(org.springframework.ai.chat.client.ChatClientRequest request, org.springframework.ai.chat.client.advisor.api.CallAdvisorChain chain) - Specified by:
adviseCallin interfaceorg.springframework.ai.chat.client.advisor.api.CallAdvisor
-
adviseStream
public reactor.core.publisher.Flux<org.springframework.ai.chat.client.ChatClientResponse> adviseStream(org.springframework.ai.chat.client.ChatClientRequest request, org.springframework.ai.chat.client.advisor.api.StreamAdvisorChain chain) - Specified by:
adviseStreamin interfaceorg.springframework.ai.chat.client.advisor.api.StreamAdvisor
-