Class ModelServer
java.lang.Object
ai.badmonkey.agentspaces.springai.model.ModelServer
- All Implemented Interfaces:
org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
Serves the fleet's model requests with this peer's
ChatModels. Each
worker loop takes a ModelRequest (by model name, or by auction), stamps
the attempt, calls the provider, and completes the take with the response, so
the answer and the request's removal land together. The take lease is renewed
while the provider works; a server that dies lets it lapse and the request
goes to another server with the next attempt number.
A streamed request writes the provider's deltas as short-leased
ModelChunks, batched by the StreamChunkingPolicy; a
ModelCancel stops the stream; and the full answer still completes the
take, so a late reader gets it whole. The server never runs tools: in Spring
AI 2.0 a ChatModel call returns tool calls to the caller.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe durations and limits a server works with. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intStarts after the AgentSpaces lifecycle (Integer.MAX_VALUE - 1024).Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionModelServer(ai.badmonkey.agentspaces.api.space.Space space, ModelCatalog catalog, ModelRequestRouter router, StreamChunkingPolicy chunking, org.springframework.scheduling.TaskScheduler scheduler, String servedBy, ModelServer.Settings settings) Creates the server. -
Method Summary
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup, isPauseable, stop
-
Field Details
-
PHASE
public static final int PHASEStarts after the AgentSpaces lifecycle (Integer.MAX_VALUE - 1024).- See Also:
-
-
Constructor Details
-
ModelServer
public ModelServer(ai.badmonkey.agentspaces.api.space.Space space, ModelCatalog catalog, ModelRequestRouter router, StreamChunkingPolicy chunking, org.springframework.scheduling.TaskScheduler scheduler, String servedBy, ModelServer.Settings settings) Creates the server.- Parameters:
space- the requests spacecatalog- the models served hererouter- which requests to takechunking- stream batchingscheduler- lease renewals and stream flushesservedBy- this peer, stamped on every answersettings- durations and concurrency
-
-
Method Details
-
served
public long served()How many requests this server has answered. -
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
getPhase
public int getPhase()- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-