Skip to content

feat: Replace TrivialAgent with canonical agent_main entrypoint#9

Merged
Mehd1b merged 1 commit into
devfrom
feature/canonical-agent-main-entrypoint
Jan 24, 2026
Merged

feat: Replace TrivialAgent with canonical agent_main entrypoint#9
Mehd1b merged 1 commit into
devfrom
feature/canonical-agent-main-entrypoint

Conversation

@Mehd1b

@Mehd1b Mehd1b commented Jan 24, 2026

Copy link
Copy Markdown
Member

Summary

Replace the hardcoded TrivialAgent::run() call in kernel-guest with the canonical extern "Rust" fn agent_main(ctx, opaque_inputs) entrypoint.

Key Changes

API Design

  • Use extern "Rust" instead of extern "C" for ABI safety with Rust types
  • 2-argument signature: agent_main(ctx: &AgentContext, opaque_inputs: &[u8])
  • AgentContext uses owned fields (no lifetimes) - clean "header" struct

New Crate: example-agent

  • Minimal example agent demonstrating the canonical entrypoint
  • Echoes input when opaque_inputs[0] == 1, empty output otherwise
  • Used for testing kernel execution flow

Refactored Crates

  • kernel-sdk: AgentContext now uses owned [u8; 32] fields, 144 bytes fixed size
  • kernel-guest: Uses extern "Rust" block, no unsafe pointer casts needed
  • agent-traits: Re-exports from kernel-sdk, deprecated legacy Agent trait
  • host-tests: Added tests for agent_main behavior

Technical Details

  • AgentContext is #[repr(C)], Clone, Copy, Debug, PartialEq, Eq
  • #[no_mangle] requires #[allow(unsafe_code)] due to Rust lint rules
  • All 88 host-tests pass, plus crate-specific tests

Test plan

  • cargo build --release passes
  • cargo test - all 88 host-tests pass
  • example-agent tests pass
  • kernel-sdk tests pass

## Summary

Replace the hardcoded TrivialAgent::run() call in kernel-guest with
the canonical extern "Rust" fn agent_main(ctx, opaque_inputs) entrypoint.

## Key Changes

### API Design
- Use `extern "Rust"` instead of `extern "C"` for ABI safety with Rust types
- 2-argument signature: `agent_main(ctx: &AgentContext, opaque_inputs: &[u8])`
- AgentContext uses owned fields (no lifetimes) - clean "header" struct

### New Crate: example-agent
- Minimal example agent demonstrating the canonical entrypoint
- Echoes input when opaque_inputs[0] == 1, empty output otherwise
- Used for testing kernel execution flow

### Refactored Crates
- kernel-sdk: AgentContext now uses owned [u8; 32] fields, 144 bytes fixed size
- kernel-guest: Uses extern "Rust" block, no unsafe pointer casts needed
- agent-traits: Re-exports from kernel-sdk, deprecated legacy Agent trait
- host-tests: Added tests for agent_main behavior

## Technical Details

- AgentContext is #[repr(C)], Clone, Copy, Debug, PartialEq, Eq
- #[no_mangle] requires #[allow(unsafe_code)] due to Rust lint rules
- All 88 host-tests pass, plus crate-specific tests
@Mehd1b
Mehd1b merged commit cb15818 into dev Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant