UOMI provides a set of high-level API functions that wrap the low-level WebAssembly calls, making it easy to develop agents without dealing with memory management and unsafe code. These functions are designed to be safe, efficient, and easy to use.
Core Functions
Logging
log(message: &str)
Logs a message to the console for debugging purposes.
pubfnlog(message:&str)
Example:
fnprocess_data(){log("Starting data processing...");// Process datalog("Data processing completed");}
Calls an AI model with the prepared request. Model can be found on the Models page
Example:
Common Usage Patterns
Complete Agent Example
File Processing Example
Performance Tips
Minimize AI Calls
Use efficient prompts
Optimize Data Handling
Process data in appropriate chunks
Avoid unnecessary copies
Use efficient data structures
Smart Logging
Remove logs for production agent
Avoid logging sensitive data
Security Considerations
Remember that these functions are part of the protected API and should not be modified. They provide a safe interface to interact with the UOMI blockchain and AI capabilities.
fn process_with_ai() {
// Prepare AI request
let prompt = format!("{{\"messages\": [{\"role\":\"user\",\"content\":\"hey\"}] }}");
let request = prepare_request(prompt);
// Call AI model
let response = call_ai_service(1, request);
// Process response
let result = String::from_utf8(response).unwrap();
log(&format!("AI response: {}", result));
}
mod utils;
#[no_mangle]
pub extern "C" fn process() {
// Log start of processing
log("Starting agent execution");
// Read input
let input = read_input();
let input_str = String::from_utf8(input).unwrap();
log(&format!("Received input: {}", input_str));
// Prepare AI request
let prompt = format!("{{\"messages\": [{\"role\":\"user\",\"content\":{}] }}", input_str);
// Call AI model
let ai_response = call_ai_service(1, request);
let result = String::from_utf8(ai_response).unwrap();
// Save output
save_output(result.as_bytes());
log("Agent execution completed");
}
mod utils;
fn process_file_content() {
// Get file content
let content = get_input_file_service();
// Process with AI
let request = prepare_request(format!("{{\"messages\": [{\"role\":\"user\",\"content\":{}] }}", String::from_utf8(content).unwrap()));
let summary = call_ai_service(1, request);
// Save results
save_output(&summary);
}