Skip to content

Commit 39291e7

Browse files
authored
fix parameter extraction in rust sdk (#3000)
1 parent 2f93724 commit 39291e7

22 files changed

+10
-38
lines changed

golem-worker-executor/tests/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ async fn get_worker_metadata(
14971497
)?
14981498
.len();
14991499
assert_eq!(metadata2.component_size, component_file_size);
1500-
assert_eq!(metadata2.total_linear_memory_size, 1769472);
1500+
assert_eq!(metadata2.total_linear_memory_size, 1638400);
15011501
Ok(())
15021502
}
15031503

sdks/rust/golem-rust-macro/src/agentic/agent_implementation_impl.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ fn build_match_arms(
197197
) -> (Vec<proc_macro2::TokenStream>, Option<&syn::ImplItemFn>) {
198198
let mut match_arms = Vec::new();
199199
let mut constructor_method = None;
200-
let mut method_index: usize = 0;
201200

202201
for item in &impl_block.items {
203202
if let syn::ImplItem::Fn(method) = item {
@@ -295,14 +294,10 @@ fn build_match_arms(
295294
},
296295
};
297296

298-
let current_method_index = method_index;
299-
method_index += 1;
300-
301297
let method_param_extraction = generate_method_param_extraction(
302298
&param_idents,
303299
&agent_type_name,
304300
method_name_str.as_str(),
305-
current_method_index,
306301
post_method_param_extraction_logic,
307302
);
308303

@@ -321,19 +316,18 @@ fn generate_method_param_extraction(
321316
param_idents: &[syn::Ident],
322317
agent_type_name: &str,
323318
method_name: &str,
324-
method_index: usize,
325319
post_method_param_extraction_logic: proc_macro2::TokenStream,
326320
) -> proc_macro2::TokenStream {
327321
let input_param_index_init = quote! {
328322
let mut input_param_index: usize = 0;
329323
let __agent_type_name = golem_rust::agentic::AgentTypeName(#agent_type_name.to_string());
330-
let __param_schemas = golem_rust::agentic::get_method_parameter_types_by_index(
324+
let __param_schemas = golem_rust::agentic::get_method_parameter_types(
331325
&__agent_type_name,
332-
#method_index,
326+
#method_name
333327
).ok_or_else(|| {
334328
golem_rust::agentic::custom_error(format!(
335-
"Internal Error: Parameter schemas not found for agent: {}, method index: {}",
336-
#agent_type_name, #method_index
329+
"Internal Error: Parameter schemas not found for agent: {}, method: {}",
330+
#agent_type_name, #method_name
337331
))
338332
})?;
339333
};

sdks/rust/golem-rust/benches/agent_registry_bench.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ test_r::enable!();
2626
mod bench {
2727
use golem_rust::agentic::{
2828
get_constructor_parameter_type, get_enriched_agent_type_by_name, get_method_parameter_type,
29-
get_method_parameter_types_by_index, register_agent_type, AgentTypeName,
30-
EnrichedAgentMethod, EnrichedElementSchema, ExtendedAgentConstructor, ExtendedAgentType,
31-
ExtendedDataSchema,
29+
register_agent_type, AgentTypeName, EnrichedAgentMethod, EnrichedElementSchema,
30+
ExtendedAgentConstructor, ExtendedAgentType, ExtendedDataSchema,
3231
};
3332
use golem_rust::golem_agentic::golem::agent::common::{AgentMode, ElementSchema, Snapshotting};
3433
use golem_wasm::golem_core_1_5_x::types::{NamedWitTypeNode, WitType, WitTypeNode};
@@ -166,27 +165,6 @@ mod bench {
166165
},
167166
);
168167

169-
// --- get_method_parameter_types_by_index (batch, Fix 4a+6) ---
170-
println!("\n--- get_method_parameter_types_by_index (batch by method index) ---");
171-
172-
bench_loop("batch all params by method index", ITERATIONS, || {
173-
black_box(get_method_parameter_types_by_index(&agent_type_name, 5));
174-
});
175-
176-
bench_loop(
177-
&format!(
178-
"batch + index into vec for {} params (new hot path)",
179-
PARAMS
180-
),
181-
ITERATIONS,
182-
|| {
183-
let schemas = get_method_parameter_types_by_index(&agent_type_name, 5).unwrap();
184-
for i in 0..PARAMS {
185-
black_box(schemas.get(i));
186-
}
187-
},
188-
);
189-
190168
// --- get_constructor_parameter_type ---
191169
println!("\n--- get_constructor_parameter_type ---");
192170

sdks/rust/golem-rust/src/agentic/agent_registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,14 @@ pub fn get_method_parameter_type(
204204
extract_parameter_schema(&method.input_schema, parameter_index)
205205
}
206206

207-
pub fn get_method_parameter_types_by_index(
207+
pub fn get_method_parameter_types(
208208
agent_type_name: &AgentTypeName,
209-
method_index: usize,
209+
method_name: &str,
210210
) -> Option<Vec<EnrichedElementSchema>> {
211211
let state = get_state();
212212
let agent_types = state.agent_types.borrow();
213213
let agent_type = agent_types.agent_types.get(agent_type_name.0.as_str())?;
214-
let method = agent_type.methods.get(method_index)?;
214+
let method = agent_type.methods.iter().find(|m| m.name == method_name)?;
215215

216216
Some(extract_all_parameter_schemas(&method.input_schema))
217217
}
823 Bytes
Binary file not shown.
-22 Bytes
Binary file not shown.
11.3 KB
Binary file not shown.
-22 Bytes
Binary file not shown.
-22 Bytes
Binary file not shown.
10.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)