Agentic Calls corrected to comply with new Architecture

This commit is contained in:
Manas Hejmadi
2025-08-03 17:49:00 +05:30
parent ed41f8446b
commit 06a71ea232
8 changed files with 34 additions and 22 deletions

View File

@@ -7,7 +7,7 @@ import 'package:genai/genai.dart';
class APIDashAgentCaller { class APIDashAgentCaller {
static APIDashAgentCaller instance = APIDashAgentCaller(); static APIDashAgentCaller instance = APIDashAgentCaller();
Future<(String? output, String error)> call( Future<dynamic> call(
APIDashAIAgent agent, { APIDashAIAgent agent, {
required WidgetRef ref, required WidgetRef ref,
required AgentInputs input, required AgentInputs input,
@@ -15,7 +15,7 @@ class APIDashAgentCaller {
final defaultAIModel = final defaultAIModel =
ref.read(settingsProvider.select((e) => e.defaultAIModel)); ref.read(settingsProvider.select((e) => e.defaultAIModel));
if (defaultAIModel == null) { if (defaultAIModel == null) {
return (null, 'NO_DEFAULT_LLM'); throw Exception('NO_DEFAULT_LLM');
} }
final baseAIRequestObject = AIRequestModel.fromJson(defaultAIModel); final baseAIRequestObject = AIRequestModel.fromJson(defaultAIModel);
final ans = await GenAIAgenticService.callAgent( final ans = await GenAIAgenticService.callAgent(

View File

@@ -0,0 +1,5 @@
export 'intermediate_rep_gen.dart';
export 'semantic_analyser.dart';
export 'stac2flutter.dart';
export 'stacgen.dart';
export 'stacmodifier.dart';

View File

@@ -1,6 +1,6 @@
import 'package:genai/agentic_engine/blueprint.dart'; import 'package:genai/agentic_engine/blueprint.dart';
const String kIntermediateRepGenSystemPrompt = """ const String _sysprompt = """
You are an expert at converting API Responses into a YAML schema tree. You are an expert at converting API Responses into a YAML schema tree.
When you get a given JSON API Response, I want you to break it down and recombine it in the form of a YAMK UI schema. When you get a given JSON API Response, I want you to break it down and recombine it in the form of a YAMK UI schema.
@@ -45,7 +45,7 @@ class IntermediateRepresentationGen extends APIDashAIAgent {
@override @override
String getSystemPrompt() { String getSystemPrompt() {
return kIntermediateRepGenSystemPrompt; return _sysprompt;
} }
@override @override

View File

@@ -1,6 +1,6 @@
import 'package:genai/agentic_engine/blueprint.dart'; import 'package:genai/agentic_engine/blueprint.dart';
const String kSemanticAnalyserSystemPrompt = """ const String _sysprompt = """
You are an expert at understanding API response structures. You are an expert at understanding API response structures.
When i provide a sample JSON response, Please give me a semantic analysis about it. When i provide a sample JSON response, Please give me a semantic analysis about it.
@@ -20,7 +20,7 @@ class ResponseSemanticAnalyser extends APIDashAIAgent {
@override @override
String getSystemPrompt() { String getSystemPrompt() {
return kSemanticAnalyserSystemPrompt; return _sysprompt;
} }
@override @override

View File

@@ -1,6 +1,6 @@
import 'package:genai/agentic_engine/blueprint.dart'; import 'package:genai/agentic_engine/blueprint.dart';
const String kIntermediateRepGenSystemPrompt = """ const String _sysprompt = """
You are an expert agent whose sole JOB is to accept FLutter-SDUI (json-like) representation You are an expert agent whose sole JOB is to accept FLutter-SDUI (json-like) representation
and convert it into actual working FLutter component. and convert it into actual working FLutter component.
@@ -22,7 +22,7 @@ class StacToFlutterBot extends APIDashAIAgent {
@override @override
String getSystemPrompt() { String getSystemPrompt() {
return kIntermediateRepGenSystemPrompt; return _sysprompt;
} }
@override @override

View File

@@ -1,6 +1,6 @@
import 'package:genai/agentic_engine/blueprint.dart'; import 'package:genai/agentic_engine/blueprint.dart';
const String kIntermediateRepGenSystemPrompt = """ const String _sysprompt = """
You are an expert agent whose sole JOB is to generate FLutter-SDUI (json-like) representation from a Text based description You are an expert agent whose sole JOB is to generate FLutter-SDUI (json-like) representation from a Text based description
and a provided Schema and a provided Schema
@@ -232,7 +232,7 @@ class StacGenBot extends APIDashAIAgent {
@override @override
String getSystemPrompt() { String getSystemPrompt() {
return kIntermediateRepGenSystemPrompt; return _sysprompt;
} }
@override @override

View File

@@ -1,6 +1,6 @@
import 'package:genai/agentic_engine/blueprint.dart'; import 'package:genai/agentic_engine/blueprint.dart';
const String kIntermediateRepGenSystemPrompt = """ const String _sysprompt = """
You are an expert agent whose sole JOB is to accept FLutter-SDUI (json-like) representation You are an expert agent whose sole JOB is to accept FLutter-SDUI (json-like) representation
and modify it to match the requests of the client. and modify it to match the requests of the client.
@@ -21,7 +21,7 @@ class SlacModifierBot extends APIDashAIAgent {
@override @override
String getSystemPrompt() { String getSystemPrompt() {
return kIntermediateRepGenSystemPrompt; return _sysprompt;
} }
@override @override

View File

@@ -1,13 +1,15 @@
import 'dart:convert'; import 'dart:convert';
import 'package:apidash/consts.dart'; import 'package:apidash/consts.dart';
import 'package:apidash/services/agentic_services/agent_caller.dart'; import 'package:apidash/services/agentic_services/agent_caller.dart';
import 'package:apidash/widgets/widget_sending.dart'; import 'package:apidash/widgets/widget_sending.dart';
import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:genai/agentic_engine/blueprint.dart';
import 'package:stac/stac.dart' as stac; import 'package:stac/stac.dart' as stac;
import '../services/agentic_services/agents/agents.dart';
void showCustomDialog(BuildContext context, String content) { void showCustomDialog(BuildContext context, String content) {
showDialog( showDialog(
context: context, context: context,
@@ -48,32 +50,37 @@ class _DialogContentsState extends ConsumerState<DialogContents> {
}); });
//STEP 1: RESPONSE_ANALYSER (call the Semantic Analysis & IRGen Bots in parallel) //STEP 1: RESPONSE_ANALYSER (call the Semantic Analysis & IRGen Bots in parallel)
final step1Res = await Future.wait([ final step1Res = await Future.wait([
APIDashAgentCaller.instance.semanticAnalyser( APIDashAgentCaller.instance.call(
ref, ResponseSemanticAnalyser(),
ref: ref,
input: AgentInputs(query: apiResponse), input: AgentInputs(query: apiResponse),
), ),
APIDashAgentCaller.instance.irGenerator( APIDashAgentCaller.instance.call(
ref, IntermediateRepresentationGen(),
ref: ref,
input: AgentInputs(variables: { input: AgentInputs(variables: {
'VAR_API_RESPONSE': apiResponse, 'VAR_API_RESPONSE': apiResponse,
}), }),
), ),
]); ]);
final SA = step1Res[0]['SEMANTIC_ANALYSIS'];
final IR = step1Res[1]['INTERMEDIATE_REPRESENTATION']; final SA = step1Res[0]?['SEMANTIC_ANALYSIS'];
final IR = step1Res[1]?['INTERMEDIATE_REPRESENTATION'];
print("Semantic Analysis: $SA"); print("Semantic Analysis: $SA");
print("Intermediate Representation: $IR"); print("Intermediate Representation: $IR");
//STEP 2: STAC_GEN (Generate the SDUI Code) //STEP 2: STAC_GEN (Generate the SDUI Code)
final sduiCode = await APIDashAgentCaller.instance.stacGenerator(
ref, final sduiCode = await APIDashAgentCaller.instance.call(
StacGenBot(),
ref: ref,
input: AgentInputs(variables: { input: AgentInputs(variables: {
'VAR_RAW_API_RESPONSE': apiResponse, 'VAR_RAW_API_RESPONSE': apiResponse,
'VAR_INTERMEDIATE_REPR': IR, 'VAR_INTERMEDIATE_REPR': IR,
'VAR_SEMANTIC_ANALYSIS': SA, 'VAR_SEMANTIC_ANALYSIS': SA,
}), }),
); );
return sduiCode['STAC'].toString(); return sduiCode?['STAC']?.toString() ?? "<NONE>";
} }
@override @override