基于注解驱动的跨架构 AI Agent 编排框架
Welcome to AiSpect! Through this manual, you can quickly learn how to integrate and use AiSpect’s intelligent capabilities in external projects.
AiSpect is an “annotation-based” Agent orchestration framework.
You do not need to manage complex LLM communication logic yourself. Just add an @AiUnitAgent annotation to your target function, and when that function is called, it will be intercepted by the corresponding Agent, using AI to process data, make judgments, or enrich results.
Place the downloaded aispect-engine-spring and its underlying dependency packages into your project’s classpath.
(Or include it via our private Maven repository)
Add the configuration in your application.yml:
aispect:
provider: gemini
default-model: gemini-2.5-flash
api-key: "${GEMINI_API_KEY:sk-xxxxxx}"
Define your business method and attach the @AiUnitAgent annotation.
@Service
public class OrderService {
// Let AI perform validity or intent checks on parameters before actually generating the order
@AiUnitAgent(name = OrderValidatorAgentImpl.class, description = "Validate order requirements")
public Order createOrder(String userRequirement) {
// ... Actual database save logic ...
return new Order();
}
}
Implement the corresponding agentClass:
@Component
public class OrderValidatorAgentImpl extends AbstractUnitAgent<Object, Order> {
@Override
public Order orchestrate(AiInvocationContext<Object> ctx) throws AiSpectException {
// This logic is called when the original method is executed. The underlying AI model can be accessed via getAiOperations(ctx)
// For example: check if userRequirement in args contains high-risk words, throw an exception to short-circuit if so,
// or call the LLM to generate specific order information and return it directly.
return new Order();
}
}
For more complex business distribution, you can go beyond a single Unit Agent and use Graph Agents to take over the workflow of an entire class.
@AiGraphAgent: Annotated at the class level, serving as the global entry point for complex workflows.@AiNode: Annotated at the method level, serving as a sub-function node that the LLM can actively schedule (similar to Tool/Skill).To ensure the rigor of process orchestration, the AiSpect engine introduces comprehensive error collection capabilities during the Bootstrap phase. The scanner will never short-circuit and exit when it encounters the first configuration error. Instead, it collects all configuration defects on the current function and prints all error logs at once.
Developers must strictly comply with the following troubleshooting constraints, otherwise the application startup will be safely intercepted by the framework:
@AiNode, its host class must be annotated with @AiGraphAgent. The framework refuses to load “orphan nodes” that have no clear entry point affiliation.@AiUnitAgent or @AiNode) are used on the same method, they must have distinct execution phases (executePhase). Furthermore, mixing the ALL phase with specific partial phases such as BEFORE/AFTER is strictly prohibited.