AI Assistant Generates Business Logic Code
Overview
In modern software development, low-code and code generation frameworks have greatly improved efficiency in project setup and basic functionality development. However, when it comes to handling complex and non-standard business logic, developers still rely heavily on manual coding. This not only slows down overall progress but also increases the risk of errors and inconsistent coding styles.
While there are already general-purpose AI programming tools (such as Cursor, Windsurf, Trae, etc.), they are often not efficient enough for business logic development—especially in domain-specific scenarios like Go project development, where targeted support is lacking.
To address this, the sponge framework integrates with multiple AI models (such as ChatGPT, Gemini, and DeepSeek) to build an AI-augmented development framework. It can automatically generate and integrate business logic code, significantly enhancing both the development experience and long-term project maintainability.
Sponge’s Solution: A Built-in AI Assistant That Understands Frameworks and Business Logic
The sponge framework comes with a built-in AI assistant that embeds generative AI capabilities directly into the development workflow. Its key advantages include:
- Framework-aware code generation: The AI assistant understands sponge’s standard project structure and layered architecture (e.g., Handler, Service, DAO), ensuring generated code is placed in the right location.
- Automated generation and merging: Developers can simply describe business requirements in natural language comments. The AI assistant then generates business logic implementations that follow project conventions and automatically merges them into the right files—no manual copy-pasting needed. It provides a complete
generate
→preview
→merge
workflow, giving developers full control while ensuring seamless integration. - Multi-model support: Users can choose from different AI backends. Sponge already supports ChatGPT, Gemini, and DeepSeek, making it easy to balance quality, performance, and cost.
Usage Example
Get an AI Assistant API Key
Obtain an API key from any of the supported platforms (one or more can be used):
Create a Service
When creating a service with sponge—whether based on SQL or Protobuf (e.g., web, gRPC, http+gRPC, gRPC Gateway)—if it uses Protobuf, the AI assistant can help generate business logic.
The only requirement is that each rpc
method in your Protobuf file must include comments describing the function’s purpose. These comments are used as AI prompts. Example:
syntax = "proto3";
package api.user.v1;
service User {
// User login with email and password
// 1. Validate request parameters: check email format and ensure password is not empty
// 2. Query user info from the database; if not found, return error code "User does not exist"
// 3. Verify password; if incorrect, return error code "Invalid password"
// 4. Check if user status is active; if disabled, return error code "User disabled"
// 5. Generate access token containing user ID and email
// 6. Update last login time and IP; log the login event to the database
rpc LoginByEmail(LoginByEmailRequest) returns (LoginByEmailReply) {
option (google.api.http) = {
post: "/api/v1/auth/login"
body: "*"
};
}
// ... other rpc methods
}
For example, see the tutorial Create Web Service Based on Protobuf.
Once the service is created, generate and merge the related API code:
make proto
At this point, beyond the standard CRUD code, you can either implement business logic manually or let the AI assistant generate and merge it automatically.
Generate Code with the AI Assistant
Open sponge’s UI;
Navigate to AI Assistant Code Generation → Generate Go Code;
Fill in the following parameters (hover over the
?
for help):- LLM type: e.g.,
deepseek
- Model: e.g.,
deepseek-chat
- API key: e.g.,
sk-xxxxxx
- Working directory: e.g.,
/home/gopher/project/user
- LLM type: e.g.,
Click Generate Code, as shown below:

Equivalent CLI Command
sponge assistant generate --type=deepseek --model=deepseek-chat --api-key=sk-xxxxxx --dir=/home/gopher/project/user
Tips
Generated Go code is stored in the same directory as your .go
file, in a .xxx.md
file (where xxx
is the LLM type, e.g., deepseek, chatgpt, gemini).
You can generate code in two modes:
File mode (recommended):
- Only processes one
.go
file. - The AI assistant scans eligible functions in the file and generates code in context.
- This targeted approach is better for real-world workflows.
- Only processes one
Directory mode:
- Processes all
.go
files in the given directory. - Multiple AI assistants (up to 10) may run concurrently depending on the number of functions.
- Performance depends on the selected model.
- Processes all
Preview the generated code in your IDE. If the result isn’t satisfactory, refine the function comments or switch to a different model for comparison.
Merge Code
The AI-generated logic code is first saved in .xxx.md
files. Once reviewed, you can merge them into the actual .go
files with sponge’s built-in merging tool.
Open sponge’s UI;
Go to AI Assistant Code Generation → Merge Go Code;
Fill in the parameters:
- LLM type: e.g.,
deepseek
. If multiple models generated code, choose the best one. - Working directory: e.g.,
/home/gopher/project/user
- Clear AI code: default
true
. Whether to delete.xxx.md
files after merging.
- LLM type: e.g.,
Click Merge Code, as shown below:

Equivalent CLI Command
sponge assistant merge --type=deepseek --dir=/home/gopher/project/user --is-clean=true
Tips
Before merging, sponge automatically backs up your .go
files. If needed, you can restore them from the backup.
Important
If you merge multiple times using different models, the most recent merge will overwrite previous results.
Clean AI-Generated Files
If you forget to check 'Auto clear AI code' when merging code, you can use the following command to batch clear all '. xxx. md' files:
sponge assistant clean --dir=/path/to/directory
Using Sponge AI Assistant on Any Go File
While the examples above focus on sponge-generated services, the AI assistant can also be used in any Go file.
Simply add a descriptive comment above a function to act as a trigger, and the AI assistant will generate the implementation. The workflow is the same, though in this case it won’t be aware of the full project structure—it will only generate code based on the function comment.
Example trigger in a .go
file:
// Describe the function’s required behavior (mandatory: used as AI prompt)
func FunctionName() {
panic("implement me") // Mandatory: AI assistant will insert code here
}