MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / agent_declaration

Method agent_declaration

aiscript-vm/src/parser/mod.rs:257–336  ·  view source on GitHub ↗
(&mut self, visibility: Visibility)

Source from the content-addressed store, hash-verified

255 }
256
257 fn agent_declaration(&mut self, visibility: Visibility) -> Option<Stmt<'gc>> {
258 self.consume(TokenType::Identifier, "Expect agent name.");
259 let name = self.previous;
260 self.scopes.push(name.lexeme.to_owned());
261 self.consume(TokenType::OpenBrace, "Expect '{' before agent body.");
262 let mut fields = HashMap::new();
263 while !self.check(TokenType::CloseBrace) && !self.check(TokenType::Fn) && !self.is_at_end()
264 {
265 let (key, value) = self.field_declaration()?;
266 match key.lexeme {
267 "instructions" | "model" | "tool_choice" => {
268 if !matches!(
269 value,
270 Expr::Literal {
271 value: Literal::String { .. },
272 ..
273 }
274 ) {
275 self.error(&format!(
276 "Field '{}' in agent declaration should be a string.",
277 key.lexeme
278 ));
279 continue;
280 }
281 }
282 "tools" => {
283 if !matches!(value, Expr::List { .. }) {
284 self.error("Field 'tools' in agent declaration should be an array.");
285 continue;
286 }
287 }
288 invalid => self.error_at(
289 key,
290 &format!("Invalid field '{}' in agent declaration.", invalid),
291 ),
292 }
293
294 if fields.contains_key(key.lexeme) {
295 self.error_at(
296 key,
297 &format!("Duplicate field '{}' in agent declaration.", key.lexeme),
298 );
299 continue;
300 }
301 fields.insert(key.lexeme, value);
302 // Consume comma after field declaration
303 if !self.check(TokenType::CloseBrace) {
304 self.consume(TokenType::Comma, "Expect ',' after field declaration.");
305 }
306 }
307
308 // Check for required fields
309 let required_fields = ["instructions"];
310 for field in required_fields {
311 if !fields.contains_key(field) {
312 self.error(&format!(
313 "Missing required field '{}' in agent declaration.",
314 field

Callers 1

declarationMethod · 0.80

Calls 9

AgentClass · 0.85
pushMethod · 0.80
checkMethod · 0.80
is_at_endMethod · 0.80
field_declarationMethod · 0.80
func_declarationMethod · 0.80
consumeMethod · 0.45
errorMethod · 0.45
error_atMethod · 0.45

Tested by

no test coverage detected