moonbitstack/moonkoog/agent does not have a README file
pub(open) trait Middleware {
fn name(Self) -> String
fn install(Self, Tools) -> Unit
async fn before_agent(Self, RunContext) -> Array[Update]
async fn wrap_model(Self, RunContext, ModelCall, async (ModelCall) -> ModelOutcome) -> ModelOutcome
async fn wrap_tool(Self, RunContext, ToolCall, async (ToolCall) -> ToolOutcome) -> ToolOutcome
async fn after_agent(Self, RunContext, AgentState) -> Array[Update]
}pub(all) suberror AgentError {
Exhausted(limit~ : Int)
Refused(reason~ : String)
Engine(GraphError)
}pub struct Agent {
runtime : Runtime
graph : Graph[AgentState, Update]
strategy_name : String
saver : &Saver?
}async fn Agent::history(self : Agent, thread : String) -> Array[Snapshot[AgentState]] raise AgentErrorasync fn Agent::resume_from(self : Agent, thread : String, answer : Json) -> String raise AgentErrorasync fn Agent::stream(self : Agent, input : String, listener : (Event) -> Unit, thread? : String) -> String raise AgentErrorpub(all) struct AgentConfig {
name : String
model : String
instructions : String?
tools : Array[ToolSpec]
options : Options
limits : Limits
middleware : Array[&Middleware]
strategy : Strategy?
structured : Structured?
events : EventHandler
exit_tool : String?
missing_tools : MissingTools
nodes : Map[String, async (Runtime, AgentState, Run) -> Array[Step[AgentState, Update]]]
}fn AgentConfig::react(model : String, name? : String, reasoning_prompt? : String, interval? : Int) -> AgentConfigfn AgentConfig::with_node(self : AgentConfig, name : String, body : async (Runtime, AgentState, Run) -> Array[Step[AgentState, Update]]) -> AgentConfigimpl FromJson for AgentStateimpl ToJson for AgentStatepub(all) enum Event {
AgentStarted(name~ : String)
AgentFinished(name~ : String, text~ : String)
AgentFailed(name~ : String, reason~ : String)
ModelStarted(name~ : String, model~ : String)
ModelFinished(name~ : String, usage~ : Usage)
ToolStarted(name~ : String, call_id~ : String)
ToolFinished(name~ : String, call_id~ : String, failed~ : Bool)
HandedOver(from~ : String, to~ : String)
NodeStarted(name~ : String)
NodeFinished(name~ : String)
}pub struct EventHandler {
listener : (Event) -> Unit
on_agent_starting : (String) -> Unit
on_agent_completed : (String) -> Unit
on_agent_execution_failed : (String) -> Unit
on_strategy_starting : (String) -> Unit
on_strategy_completed : (String, String) -> Unit
on_llm_call_starting : (Request) -> Request
on_llm_call_completed : (Reply) -> Reply
on_llm_streaming_starting : (Request) -> Unit
on_llm_streaming_frame : (String) -> Unit
on_llm_streaming_completed : (Reply) -> Unit
on_tool_call_starting : (String, Json) -> Json
on_tool_call_completed : (String, String) -> String
on_tool_call_failed : (String, String) -> Unit
on_tool_validation_failed : (String, Json, String) -> Unit
on_node_execution_starting : (String) -> Unit
on_node_execution_completed : (String) -> Unit
on_node_execution_failed : (String, String) -> Unit
on_subgraph_execution_starting : (String) -> Unit
on_subgraph_execution_completed : (String, String) -> Unit
}fn EventHandler::intercept_llm_call_completed(self : EventHandler, handler : (Reply) -> Reply) -> EventHandlerfn EventHandler::intercept_llm_call_starting(self : EventHandler, handler : (Request) -> Request) -> EventHandlerfn EventHandler::intercept_tool_call_completed(self : EventHandler, handler : (String, String) -> String) -> EventHandlerfn EventHandler::intercept_tool_call_starting(self : EventHandler, handler : (String, Json) -> Json) -> EventHandlerfn EventHandler::on_agent_completed(self : EventHandler, handler : (String) -> Unit) -> EventHandlerfn EventHandler::on_agent_execution_failed(self : EventHandler, handler : (String) -> Unit) -> EventHandlerfn EventHandler::on_llm_call_completed(self : EventHandler, handler : (Reply) -> Unit) -> EventHandlerfn EventHandler::on_llm_call_starting(self : EventHandler, handler : (Request) -> Unit) -> EventHandlerfn EventHandler::on_llm_streaming_completed(self : EventHandler, handler : (Reply) -> Unit) -> EventHandlerfn EventHandler::on_llm_streaming_frame(self : EventHandler, handler : (String) -> Unit) -> EventHandlerfn EventHandler::on_llm_streaming_starting(self : EventHandler, handler : (Request) -> Unit) -> EventHandlerfn EventHandler::on_node_execution_completed(self : EventHandler, handler : (String) -> Unit) -> EventHandlerfn EventHandler::on_node_execution_failed(self : EventHandler, handler : (String, String) -> Unit) -> EventHandlerfn EventHandler::on_node_execution_starting(self : EventHandler, handler : (String) -> Unit) -> EventHandlerfn EventHandler::on_strategy_completed(self : EventHandler, handler : (String, String) -> Unit) -> EventHandlerfn EventHandler::on_strategy_starting(self : EventHandler, handler : (String) -> Unit) -> EventHandlerfn EventHandler::on_subgraph_execution_completed(self : EventHandler, handler : (String, String) -> Unit) -> EventHandlerfn EventHandler::on_subgraph_execution_starting(self : EventHandler, handler : (String) -> Unit) -> EventHandlerfn EventHandler::on_tool_call_completed(self : EventHandler, handler : (String, String) -> Unit) -> EventHandlerfn EventHandler::on_tool_call_failed(self : EventHandler, handler : (String, String) -> Unit) -> EventHandlerfn EventHandler::on_tool_call_starting(self : EventHandler, handler : (String, Json) -> Unit) -> EventHandlerfn EventHandler::on_tool_validation_failed(self : EventHandler, handler : (String, Json, String) -> Unit) -> EventHandlerpub struct FirstChoice {
}pub(all) enum HistoryPolicy {
Whole
FromLast(Int)
}pub(all) struct Limits {
iterations : Int
tool_calls : Int
steps : Int
}pub(all) enum MissingTools {
Keep
Convert
ConvertAll
}impl Chooser for ModelChoicepub(all) enum ModelOutcome {
Replied(Reply)
Failed(reason~ : String, retryable~ : Bool)
Halted(String)
}pub(all) enum NodeKind {
Start(then~ : String)
Request(RequestMode)
Execute(ExecuteMode)
Compress(HistoryPolicy)
Finish
Think(prompt~ : String, every~ : Int)
Advise(String)
Custom(String)
Turn(mode~ : RequestMode, then~ : String)
Delegate(Graph[AgentState, Update])
}pub(all) struct Options {
temperature : Double?
max_tokens : Int?
choice : ToolChoice
stop : Array[String]
extra : Map[String, Json]
}pub struct Passthrough {
label : String
}impl Middleware for Passthroughasync fn after_agent(_self : Passthrough, _context : RunContext, _state : AgentState) -> Array[Update]async fn wrap_model(_self : Passthrough, _context : RunContext, call : ModelCall, next : async (ModelCall) -> ModelOutcome) -> ModelOutcomeasync fn wrap_tool(_self : Passthrough, _context : RunContext, call : ToolCall, next : async (ToolCall) -> ToolOutcome) -> ToolOutcomeasync fn Passthrough::after_agent(_self : Passthrough, _context : RunContext, _state : AgentState) -> Array[Update]async fn Passthrough::wrap_model(_self : Passthrough, _context : RunContext, call : ModelCall, next : async (ModelCall) -> ModelOutcome) -> ModelOutcomeasync fn Passthrough::wrap_tool(_self : Passthrough, _context : RunContext, call : ToolCall, next : async (ToolCall) -> ToolOutcome) -> ToolOutcomepub(all) enum RequestMode {
Tools
NoTools
OnlyCalling
ForceOne(String)
Choice(Int)
Streaming
StructuredOutput
}pub struct Runtime {
name : String
provider : &Provider
model : String
instructions : String?
tools : Tools
options : Options
limits : Limits
middleware : Array[&Middleware]
events : EventHandler
structured : Structured?
chooser : &Chooser?
exit_tool : String?
missing_tools : MissingTools
custom : Map[String, async (Runtime, AgentState, Run) -> Array[Step[AgentState, Update]]]
nodes : Array[String]
}fn ToolSpec::new(name~ : String, description~ : String, run~ : async (Json, RunContext) -> String, schema? : Json) -> ToolSpecfn Tools::register(self : Tools, name~ : String, description~ : String, run~ : async (Json, RunContext) -> String, schema? : Json) -> Unitasync fn after_agent_hooks(runtime : Runtime, context : RunContext, state : AgentState) -> Array[Update]let agent_node : Stringasync fn compress(runtime : Runtime, context : RunContext, messages : Array[Message], policy : HistoryPolicy) -> Compressedlet error_key : Stringfn error_text(error : Error) -> Stringlet handoff_key : Stringasync fn node_agent(runtime : Runtime, then : String, state : AgentState, run : Run) -> Array[Step[AgentState, Update]]async fn node_compress(runtime : Runtime, policy : HistoryPolicy, state : AgentState, run : Run) -> Array[Step[AgentState, Update]]async fn node_custom(runtime : Runtime, name : String, state : AgentState, run : Run) -> Array[Step[AgentState, Update]]async fn node_execute(runtime : Runtime, mode : ExecuteMode, state : AgentState, run : Run) -> Array[Step[AgentState, Update]]async fn node_finish(runtime : Runtime, state : AgentState, run : Run) -> Array[Step[AgentState, Update]]async fn node_request(runtime : Runtime, mode : RequestMode, state : AgentState, run : Run) -> Array[Step[AgentState, Update]]async fn node_request_to(runtime : Runtime, mode : RequestMode, then : String, state : AgentState, run : Run) -> Array[Step[AgentState, Update]]async fn node_think(runtime : Runtime, state : AgentState, run : Run, prompt~ : String, every~ : Int) -> Array[Step[AgentState, Update]]async fn pipeline_model(runtime : Runtime, context : RunContext, call : ModelCall, mode : RequestMode) -> ModelOutcomeInstall
Download zipmoonkoog — an agent framework for MoonBit: prebuilt agents and strategies over the moonstate graph engine, a middleware pipeline, planning, multi-agent composition, and the protocol adapters that put an agent behind MCP, A2A, ACP and the Agent Protocol.