pub struct AgentContext {
pub mesh_name: String,
/* private fields */
}Expand description
Runtime context provided to agents during lifecycle and message handling.
The context gives agents access to mesh information and utilities for interacting with the request/response system.
§Example
async fn on_message(&mut self, msg: Message, ctx: &mut AgentContext) -> Result<()> {
println!("Running in mesh: {}", ctx.mesh_name);
if let Some(id) = msg.correlation_id() {
ctx.report_result(&id, "Done!".to_string());
}
Ok(())
}Fields§
§mesh_name: StringThe name of the mesh this agent is running in.
Implementations§
Source§impl AgentContext
impl AgentContext
Sourcepub fn new(mesh_name: String, request_queue: Option<Arc<RequestQueue>>) -> Self
pub fn new(mesh_name: String, request_queue: Option<Arc<RequestQueue>>) -> Self
Create a new agent context.
§Arguments
mesh_name- Name of the meshrequest_queue- Optional request queue for request/response pattern
Examples found in repository?
examples/llm_ollama.rs (line 39)
23async fn main() -> Result<()> {
24 println!("=== Ceylon Runtime - LLM Ollama Example ===\n");
25
26 // Create an LLM agent using Ollama with gemma3:latest model
27 // No API key is required for Ollama (local inference)
28 let mut agent = LlmAgent::builder("gemma_agent", "ollama::gemma3:latest")
29 .with_system_prompt(
30 "You are a helpful AI assistant. Be concise and informative in your responses.",
31 )
32 .with_temperature(0.7)
33 .with_max_tokens(1024)
34 .build()?;
35
36 println!("✓ LLM Agent created successfully with Ollama gemma3:latest\n");
37
38 // Create an agent context for the conversation
39 let mut ctx = AgentContext::new("gemma_demo_mesh".to_string(), None);
40
41 // Example 1: Simple greeting
42 println!("--- Example 1: Simple Greeting ---");
43 let prompt1 = "Hello! What are you capable of?";
44 println!("User: {}", prompt1);
45
46 match agent.send_message_and_get_response(prompt1, &mut ctx).await {
47 Ok(response) => {
48 println!("Assistant: {}\n", response);
49 }
50 Err(e) => {
51 eprintln!("Error: {}\n", e);
52 eprintln!("Make sure Ollama is running and gemma3:latest model is available.");
53 eprintln!("Pull the model with: ollama pull gemma3:latest");
54 return Err(e);
55 }
56 }
57
58 // Example 2: Technical question
59 println!("--- Example 2: Technical Question ---");
60 let prompt2 = "Explain what an AI agent is in 2-3 sentences.";
61 println!("User: {}", prompt2);
62
63 match agent.send_message_and_get_response(prompt2, &mut ctx).await {
64 Ok(response) => {
65 println!("Assistant: {}\n", response);
66 }
67 Err(e) => {
68 eprintln!("Error: {}\n", e);
69 return Err(e);
70 }
71 }
72
73 // Example 3: Creative task
74 println!("--- Example 3: Creative Task ---");
75 let prompt3 = "Write a haiku about programming.";
76 println!("User: {}", prompt3);
77
78 match agent.send_message_and_get_response(prompt3, &mut ctx).await {
79 Ok(response) => {
80 println!("Assistant: {}\n", response);
81 }
82 Err(e) => {
83 eprintln!("Error: {}\n", e);
84 return Err(e);
85 }
86 }
87
88 println!("=== Example completed successfully! ===");
89 Ok(())
90}Sourcepub fn report_result(&self, request_id: &str, response: String)
pub fn report_result(&self, request_id: &str, response: String)
Report a result for a pending request.
Call this to send a response back to the requester when handling a message with a correlation ID.
Sourcepub fn has_request_queue(&self) -> bool
pub fn has_request_queue(&self) -> bool
Check if this context has a request queue available.
Auto Trait Implementations§
impl Freeze for AgentContext
impl !RefUnwindSafe for AgentContext
impl Send for AgentContext
impl Sync for AgentContext
impl Unpin for AgentContext
impl !UnwindSafe for AgentContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more