Logo GenPRES

Agent Module

Functions and values

Function or value Description

Agent.createReply processor

Full Usage: Agent.createReply processor

Parameters:
    processor : 'Request -> 'Reply - A function to process each request and produce a reply.

Returns: Agent<'Request * AsyncReplyChannel<'Reply>> An Agent instance.
Type parameters: 'Request, 'Reply

Creates and starts an agent that supports request-reply messaging. The processor function computes a reply for each request.

processor : 'Request -> 'Reply

A function to process each request and produce a reply.

Returns: Agent<'Request * AsyncReplyChannel<'Reply>>

An Agent instance.

Agent.createReplyAsync processor

Full Usage: Agent.createReplyAsync processor

Parameters:
    processor : 'Request -> Async<'Reply> - An async function to process each request and produce a reply.

Returns: Agent<'Request * AsyncReplyChannel<'Reply>> An Agent instance.
Type parameters: 'Request, 'Reply

Creates and starts an agent that supports request-reply messaging with an async processor function. Unlike createReply, the processor returns Async<'Reply>, so the agent can await async operations (e.g., inter-agent calls) without blocking a thread pool thread.

processor : 'Request -> Async<'Reply>

An async function to process each request and produce a reply.

Returns: Agent<'Request * AsyncReplyChannel<'Reply>>

An Agent instance.

Agent.createSimple processor

Full Usage: Agent.createSimple processor

Parameters:
    processor : 'T -> unit - A function to process each message.

Returns: Agent<'T> An Agent instance.
Type parameters: 'T

Creates and starts a simple agent that processes messages of type 'T in a loop. The processor function is called for each message received. This agent does not maintain state between messages and will not reply.

processor : 'T -> unit

A function to process each message.

Returns: Agent<'T>

An Agent instance.

Agent.createStateful (initialState, processor)

Full Usage: Agent.createStateful (initialState, processor)

Parameters:
    initialState : 'State - The initial state value.
    processor : 'State -> 'T -> 'State - A function to process each message and update the state.

Returns: Agent<'T> An Agent instance.
Type parameters: 'T, 'State

Creates and starts a stateful agent that maintains state of type 'State. The processor function updates the state for each message received. This agent does not reply to messages.

initialState : 'State

The initial state value.

processor : 'State -> 'T -> 'State

A function to process each message and update the state.

Returns: Agent<'T>

An Agent instance.

Agent.createStatefulReply (initialState, processor)

Full Usage: Agent.createStatefulReply (initialState, processor)

Parameters:
    initialState : 'State - The initial state value.
    processor : 'State -> 'Request -> 'Reply * 'State - A function to process each request and update the state.

Returns: Agent<'Request * AsyncReplyChannel<'Reply>> An Agent instance.
Type parameters: 'Request, 'Reply, 'State

Creates and starts a stateful agent that supports request-reply messaging. The processor function computes a reply and updates the state for each request.

initialState : 'State

The initial state value.

processor : 'State -> 'Request -> 'Reply * 'State

A function to process each request and update the state.

Returns: Agent<'Request * AsyncReplyChannel<'Reply>>

An Agent instance.

Agent.dispose agent

Full Usage: Agent.dispose agent

Parameters:
    agent : Agent<'a> - The agent instance.

Type parameters: 'a

Disposes the agent and cancels its processing.

agent : Agent<'a>

The agent instance.

Agent.getCurrentQueueLength agent

Full Usage: Agent.getCurrentQueueLength agent

Parameters:
    agent : Agent<'a> - The agent instance.

Returns: int The number of queued messages.
Type parameters: 'a

Gets the current number of messages in the agent's queue.

agent : Agent<'a>

The agent instance.

Returns: int

The number of queued messages.

Agent.getDefaultTimeout agent

Full Usage: Agent.getDefaultTimeout agent

Parameters:
    agent : Agent<'a> - The agent instance.

Returns: int The default timeout in milliseconds.
Type parameters: 'a

Gets the default timeout for reply operations on the agent.

agent : Agent<'a>

The agent instance.

Returns: int

The default timeout in milliseconds.

Agent.post msg agent

Full Usage: Agent.post msg agent

Parameters:
    msg : 'a
    agent : Agent<'a>

Returns: bool
Type parameters: 'a
msg : 'a
agent : Agent<'a>
Returns: bool

Agent.postAndAsyncReply msg agent

Full Usage: Agent.postAndAsyncReply msg agent

Parameters:
Returns: Async<'b> An Async computation returning the reply.
Type parameters: 'a, 'b

Posts a request to the agent and asynchronously waits for a reply.

msg : 'a

The request message.

agent : Agent<'a * AsyncReplyChannel<'b>>

The agent instance.

Returns: Async<'b>

An Async computation returning the reply.

Agent.postAndAsyncReplyTask msg agent

Full Usage: Agent.postAndAsyncReplyTask msg agent

Parameters:
Returns: Task<'b> A Task returning the reply.
Type parameters: 'a, 'b

Posts a request to the agent and returns a Task that completes with the reply.

msg : 'a

The request message.

agent : Agent<'a * AsyncReplyChannel<'b>>

The agent instance.

Returns: Task<'b>

A Task returning the reply.

Agent.postAndReply msg agent

Full Usage: Agent.postAndReply msg agent

Parameters:
Returns: 'b The reply value.
Type parameters: 'a, 'b

Posts a request to the agent and synchronously waits for a reply. When DefaultTimeout is Timeout.Infinite, a configurable fallback timeout is used (AGENT_REPLY_TIMEOUT_MS environment variable, default 30 000 ms). Throws if the reply times out.

msg : 'a

The request message.

agent : Agent<'a * AsyncReplyChannel<'b>>

The agent instance.

Returns: 'b

The reply value.

Agent.postAndTryAsyncReply timeout msg agent

Full Usage: Agent.postAndTryAsyncReply timeout msg agent

Parameters:
    timeout : int - Timeout in milliseconds.
    msg : 'a - The request message.
    agent : Agent<'a * AsyncReplyChannel<'b>> - The agent instance.

Returns: Async<'b option> An Async computation returning Some(reply) or None if timed out.
Type parameters: 'a, 'b

Posts a request to the agent and asynchronously tries to receive a reply within the specified timeout.

timeout : int

Timeout in milliseconds.

msg : 'a

The request message.

agent : Agent<'a * AsyncReplyChannel<'b>>

The agent instance.

Returns: Async<'b option>

An Async computation returning Some(reply) or None if timed out.

Agent.setDefaultTimeout timeout agent

Full Usage: Agent.setDefaultTimeout timeout agent

Parameters:
    timeout : int - Timeout in milliseconds.
    agent : Agent<'a> - The agent instance.

Type parameters: 'a

Sets the default timeout for reply operations on the agent.

timeout : int

Timeout in milliseconds.

agent : Agent<'a>

The agent instance.

Agent.stopAndDispose stopMsg agent

Full Usage: Agent.stopAndDispose stopMsg agent

Parameters:
Returns: Async<unit>
Type parameters: 'T
stopMsg : AsyncReplyChannel<unit> -> 'T
agent : Agent<'T>
Returns: Async<unit>

Agent.tryPostAndReply timeout msg agent

Full Usage: Agent.tryPostAndReply timeout msg agent

Parameters:
    timeout : int - Timeout in milliseconds.
    msg : 'a - The request message.
    agent : Agent<'a * AsyncReplyChannel<'b>> - The agent instance.

Returns: 'b option Some(reply) if successful, None if timed out.
Type parameters: 'a, 'b

Posts a request to the agent and tries to synchronously receive a reply within the specified timeout.

timeout : int

Timeout in milliseconds.

msg : 'a

The request message.

agent : Agent<'a * AsyncReplyChannel<'b>>

The agent instance.

Returns: 'b option

Some(reply) if successful, None if timed out.

Type something to start searching.