Skip to main content

Crate nenjo_tool_api

Crate nenjo_tool_api 

Source
Expand description

Shared tool contracts for Nenjo agents, model providers, and runtimes.

This crate owns the common tool API surface used across the Nenjo workspace. It is deliberately independent from the rest of the workspace so model integrations, SDK code, and worker runtimes can agree on tool schemas and execution results without depending on each other.

The main entry points are:

§Example

use async_trait::async_trait;
use serde_json::json;
use nenjo_tool_api::{Tool, ToolCategory, ToolResult};

struct EchoTool;

#[async_trait]
impl Tool for EchoTool {
    fn name(&self) -> &str {
        "echo"
    }

    fn description(&self) -> &str {
        "Echoes a message back to the caller."
    }

    fn parameters_schema(&self) -> serde_json::Value {
        json!({
            "type": "object",
            "properties": {
                "message": { "type": "string" }
            },
            "required": ["message"]
        })
    }

    fn category(&self) -> ToolCategory {
        ToolCategory::Read
    }

    async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {
        Ok(ToolResult::success(
            args["message"].as_str().unwrap_or_default(),
        ))
    }
}

Re-exports§

pub use async_ops::AsyncControl;
pub use async_ops::AsyncControlRejection;
pub use async_ops::AsyncControlRejectionReason;
pub use async_ops::AsyncControlResult;
pub use async_ops::AsyncControlResultStatus;
pub use async_ops::AsyncControls;
pub use async_ops::AsyncOperationKind;
pub use async_ops::AsyncOperationSignalKind;
pub use async_ops::AsyncOperationStartReceipt;
pub use async_ops::AsyncOperationStatus;
pub use async_ops::INSPECT_TOOL_NAME;
pub use async_ops::InspectOperationsArgs;
pub use async_ops::SEND_INPUT_TOOL_NAME;
pub use async_ops::STOP_TOOL_NAME;
pub use async_ops::SendOperationInputArgs;
pub use async_ops::StopOperationsArgs;
pub use async_ops::WAIT_TOOL_NAME;
pub use async_ops::WaitOperationsArgs;
pub use async_ops::deserialize_u64_from_json_number;
pub use async_ops::deserialize_usize_from_json_number;
pub use async_ops::inspect_operations_parameters_schema;
pub use async_ops::send_operation_input_parameters_schema;
pub use async_ops::stop_operations_parameters_schema;
pub use async_ops::wait_operations_parameters_schema;

Modules§

async_ops
Shared contracts for model-visible async operation tools.

Structs§

ArtifactId
Immutable artifact identity.
ArtifactInput
Durable, unresolved artifact input carried through tools and conversations.
ArtifactInstruction
Optional, bounded instruction associated with an artifact input.
ArtifactRef
Storage-neutral reference to one immutable artifact revision.
ArtifactSize
Authoritative plaintext byte length of an immutable artifact.
MediaType
Parsed, concrete MIME type for immutable artifact plaintext.
Sha256Digest
Canonical SHA-256 digest in sha256:<hex> form.
ToolCall
A tool call requested by the LLM.
ToolOutput
Ordered, serializable tool output without decrypted bytes or host paths.
ToolResult
Result of a tool execution.
ToolResultMessage
A tool result to feed back to the LLM.
ToolSecurity
SDK-level tool construction policy.
ToolSpec
Full specification of a tool for LLM registration.

Enums§

ArtifactInputSource
Origin of an artifact in an agent input.
ToolAutonomy
High-level autonomy requested while constructing runtime tools.
ToolCategory
Classifies a tool’s side-effect profile for filtering and model guidance.
ToolOrigin
Runtime ownership surface for a tool.
ToolOutputPart
One ordered part of a tool’s durable output.

Traits§

Tool
Core tool trait for agent capabilities.

Functions§

is_utf8_text_media_type
Classify storage-neutral media types whose plaintext bytes may be decoded as UTF-8.
sanitize_tool_name
Sanitize a tool function name to match the strict OpenAI pattern ^[a-zA-Z0-9_-]+$.
sanitize_tool_name_lenient
Light sanitization for lenient providers (Ollama) while preserving dots used in MCP namespaced tool names.