Skip to main content

agents_proc_macros/
lib.rs

1mod agent;
2mod tool;
3
4use proc_macro::TokenStream;
5use syn::{DeriveInput, parse_macro_input};
6
7/// Derives `agents::agent::Agent` by delegating to an inner field marked with `#[agent]`.
8///
9/// ```rust
10/// use agents::{Agent, SessionAgent};
11///
12/// #[derive(Agent)]
13/// struct EchoAgent {
14///     #[agent]
15///     inner: SessionAgent<String, (), (), String>,
16/// }
17/// ```
18#[proc_macro_derive(Agent, attributes(agent))]
19pub fn agent(item: TokenStream) -> TokenStream {
20    let input = parse_macro_input!(item as DeriveInput);
21    agent::expand(input)
22        .unwrap_or_else(|error| error.into_compile_error())
23        .into()
24}
25
26/// Derives the typed tool metadata needed by `SessionAgent`.
27///
28/// ```rust
29/// use schemars::JsonSchema;
30/// use serde::{Deserialize, Serialize};
31///
32/// #[derive(agents::Tool)]
33/// #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
34/// enum EchoTool {
35///     #[agent_tool(name = "echo_text", description = "Echo the provided text.")]
36///     Echo { text: String },
37/// }
38/// ```
39#[proc_macro_derive(Tool, attributes(agent_tool))]
40pub fn agent_tool(item: TokenStream) -> TokenStream {
41    let input = parse_macro_input!(item as DeriveInput);
42    tool::expand(input)
43        .unwrap_or_else(|error| error.into_compile_error())
44        .into()
45}