Skip to main content

Crate cognis_macros

Crate cognis_macros 

Source
Expand description

Proc macros for the Cognis framework.

§Macros

  • tool#[cognis::tool] attribute that generates a cognis_core::tools::BaseTool implementation from an async fn (or from an impl block containing one). Uses [schemars] under the hood for parameter schema generation.
  • GraphState — derive macro for graph state schemas with per-field reducers (see attributes #[reducer(append|last_value|add|merge)]).

§JSON Schema generation

For #[derive(JsonSchema)] on your own structs/enums, use the re-export at cognis_core::JsonSchema (which is schemars::JsonSchema). The legacy hand-rolled JsonSchema / ToolSchema derives in this crate were removed in favor of the upstream schemars crate, which supports recursive types, $ref/definitions, doc-comment → description, and richer attribute syntax.

use cognis_core::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(JsonSchema, Serialize, Deserialize)]
struct SearchFilter {
    /// Minimum relevance score
    min_score: f64,
    /// Categories to include
    categories: Vec<String>,
}

let schema = serde_json::to_value(schemars::schema_for!(SearchFilter)).unwrap();

Attribute Macros§

tool
#[cognis::tool] — attribute macro that generates a [cognis_core::tools::BaseTool] implementation from an async fn.
tools_impl
#[tools_impl] — outer attribute that scans an impl block for inner #[tool]-marked async methods and generates one [cognis_core::tools::BaseTool] wrapper per method, plus an into_tools() collector method on the user’s struct.

Derive Macros§

GraphState
Derive macro for generating graph state schemas with per-field reducers.
GraphStateV2
#[derive(GraphStateV2)] — v2-shape state derive that emits a typed sibling <Name>Update struct and an impl GraphState for <Name>. Use in v2 code via the re-export cognis_core::GraphState (the rename happens in cognis-core’s lib.rs in Plan #2).