1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//! Procedural macros for the radkit agent framework.
//!
//! This crate provides attribute macros for defining A2A-compliant skills and tools.
// Common pattern in proc macro crates
use TokenStream;
use parse_macro_input;
/// Attribute macro for defining A2A skills with metadata.
///
/// This macro generates the `SkillMetadata` and implements the `RegisteredSkill` trait
/// for the annotated struct, making it usable with the radkit agent builder.
///
/// # Required Parameters
///
/// - `id`: A unique identifier for the skill (String)
/// - `name`: A human-readable name for the skill (String)
/// - `description`: A detailed description of what the skill does (String)
///
/// # Optional Parameters
///
/// - `tags`: Array of keywords describing the skill's capabilities (default: [])
/// - `examples`: Array of example prompts or scenarios (default: [])
/// - `input_modes`: Array of supported input MIME types (default: [])
/// - `output_modes`: Array of supported output MIME types (default: [])
///
/// # MIME Type Validation
///
/// The macro validates `input_modes` and `output_modes` against a list of common MIME types.
/// If an invalid type is provided, a compile error will be generated with suggestions.
///
/// # Example
///
/// ```ignore
/// use radkit::prelude::*;
///
/// #[skill(
/// id = "summarize_text",
/// name = "Text Summarizer",
/// description = "Summarizes long text documents into concise summaries",
/// tags = ["text", "summarization", "nlp"],
/// examples = [
/// "Summarize this article",
/// "Give me a brief summary of this document"
/// ],
/// input_modes = ["text/plain", "text/markdown"],
/// output_modes = ["text/plain", "application/json"]
/// )]
/// pub struct SummarizeTextSkill;
///
/// #[async_trait]
/// impl SkillHandler for SummarizeTextSkill {
/// async fn on_request(
/// &self,
/// task_context: &mut TaskContext,
/// context: &Context,
/// runtime: &dyn Runtime,
/// content: Content,
/// ) -> Result<OnRequestResult, AgentError> {
/// // Implementation here
/// Ok(OnRequestResult::Completed {
/// message: Some(Content::text("Summary here")),
/// artifacts: vec![],
/// })
/// }
/// }
/// ```
///
/// # Generated Code
///
/// The macro generates:
/// 1. A static `SkillMetadata` constant named `{STRUCT_NAME}_METADATA`
/// 2. An implementation of `RegisteredSkill` trait for the struct
///
/// This allows the skill to be registered with an agent using `.with_skill()`:
///
/// ```ignore
/// let agent = AgentBuilder::new()
/// .with_skill(SummarizeTextSkill)
/// .build(runtime)?;
/// ```
/// Attribute macro for defining tools with automatic parameter extraction.
///
/// This macro generates a zero-sized struct with the function name and implements
/// the `BaseTool` trait directly, eliminating manual parameter extraction and JSON schema construction.
///
/// The function name is used as the tool name, so choose function names that accurately
/// describe the tool's purpose.
///
/// # Required Parameters
///
/// - `description`: A detailed description of what the tool does (String)
///
/// # Example
///
/// ```ignore
/// use radkit::tools::{ToolResult, ToolContext};
/// use radkit_macros::tool;
/// use serde::{Deserialize};
/// use schemars::JsonSchema;
/// use serde_json::json;
///
/// #[derive(Deserialize, JsonSchema)]
/// struct AddArgs {
/// a: i64,
/// b: i64,
/// }
///
/// #[tool(description = "Add two numbers")]
/// async fn add(args: AddArgs) -> ToolResult {
/// ToolResult::success(json!({"sum": args.a + args.b}))
/// }
///
/// // With ToolContext
/// #[derive(Deserialize, JsonSchema)]
/// struct SaveArgs {
/// key: String,
/// value: String,
/// }
///
/// #[tool(description = "Save state")]
/// async fn save_state(args: SaveArgs, ctx: &ToolContext<'_>) -> ToolResult {
/// ctx.state().set_state(&args.key, json!(args.value));
/// ToolResult::success(json!({"saved": true}))
/// }
/// ```
///
/// # Generated Code
///
/// The macro transforms the async function into a zero-sized struct that implements
/// `BaseTool`. Parameters are automatically deserialized using serde and the JSON
/// schema is generated using schemars. The function name becomes both the struct
/// name and the tool name visible to the LLM.
///
/// # Usage
///
/// ```ignore
/// // Pass the tool struct directly to with_tool() - no function call!
/// let worker = LlmWorker::builder(llm)
/// .with_tool(add) // ← Not add()
/// .with_tool(save_state) // ← Not save_state()
/// .build();
/// ```