nyxcore-systems
7 min read

Cracking the Code: Injecting Intent to Guide AI to Production-Ready Implementations

We tackled a common challenge in AI-driven development: getting large language models to generate truly production-ready, feature-complete code, not just stubs. Our breakthrough? Explicitly injecting the workflow's ultimate goal into the prompt.

AILLMTypeScriptPrompt EngineeringCode GenerationDevOpsDebugging

As developers, we're constantly pushing the boundaries of what AI can do, especially when it comes to automating our own workflows. One of the holy grails is having an AI reliably generate complex, production-ready code. We're not talking about simple boilerplate; we're talking about entire API implementations, complete with authentication, streaming, and even defense against prompt injection.

This past week, we hit a significant milestone in that quest. Our goal was ambitious: make our auto-generated implementation prompt—the final, critical step in our AI-powered workflow—match, and ideally exceed, the quality of a meticulously hand-crafted "gold standard." This meant complete TypeScript code, codebase-grounded paths, and absolutely no stubs.

And I'm thrilled to report: mission accomplished. Our latest auto-generated output clocks in at a whopping 610 lines, delivering a complete persona API with auth, streaming, and prompt injection defense.

The Core Problem: Losing Sight of the Goal

Our journey to this "done" state wasn't without its detours. Earlier workflow runs were producing baffling results. Instead of code for our core "rent-a-persona" feature, the AI was fixating on supporting infrastructure like billing systems. It was like asking for directions to the beach and getting a detailed itinerary for the bus depot.

The root cause was clear: our implementation prompt generator, while powerful, was only seeing the outputs of preceding workflow steps. It was analyzing the granular details of security, audit logs, and payment processing—all valid supporting concerns—but it completely missed the overarching purpose of the workflow: building the persona API itself. The AI was diligently connecting the dots, but it didn't know which picture it was supposed to be drawing.

The Breakthrough: Injecting the Workflow's Intent

The solution, once we identified the problem, felt almost elegant in its simplicity: explicitly inject the workflow's high-level goal directly into the implementation prompt.

We introduced a new workflowGoal field into our PromptInputParams. This critical piece of context, comprising the workflow.name and workflow.description, is now rendered prominently at the top of the user message as a # FEATURE GOAL section.

Here's a conceptual look at how we integrated it:

typescript
// src/server/services/implementation-prompt-generator.ts

interface PromptInputParams {
  // ... existing parameters
  workflowGoal: {
    name: string;
    description: string;
  };
}

async function buildImplementationPromptInput(params: PromptInputParams): Promise<string> {
  const { workflowGoal, /* ...other params */ } = params;

  let prompt = `# FEATURE GOAL\n`;
  prompt += `Feature Name: ${workflowGoal.name}\n`;
  prompt += `Feature Description: ${workflowGoal.description}\n\n`;
  prompt += `# SYNTHESIS DIRECTIVE\n`;
  prompt += `Synthesize ALL preceding steps and information into a single, cohesive, production-ready implementation plan for the "${workflowGoal.name}" feature. Focus exclusively on delivering the core functionality described above, leveraging the provided context.\n\n`;
  // ... rest of the prompt assembly
  return prompt;
}

// src/server/services/workflow-engine.ts (excerpt)
// ... around line ~2519
const implementationPromptInput = buildImplementationPromptInput({
  // ... other parameters
  workflowGoal: {
    name: workflow.name,
    description: workflow.description,
  },
});

This # FEATURE GOAL section acts as an anchor, forcing the LLM to synthesize all subsequent information through the lens of that specific feature. It's a powerful reminder to stay on target.

What Got Done: The Technical Rundown

With the core problem identified and a solution implemented, here's a quick rundown of the technical steps:

  • Model Upgrade: We added gemini-2.5-pro to our MODEL_CATALOG in src/lib/constants.ts. We were previously only using gemini-2.5-flash for this step, and the "pro" model's enhanced capabilities were crucial for generating higher-quality, more complex code.
  • Goal Injection Implementation: As detailed above, we injected the workflowGoal into src/server/services/implementation-prompt-generator.ts and passed workflow.name + workflow.description from src/server/services/workflow-engine.ts.
  • Robust Testing: All four unit tests in tests/unit/implementation-prompt-generator.test.ts were updated to reflect the new workflowGoal field, ensuring our prompt generation logic remains sound.
  • Deployment: Two key commits (08269a6 for the model catalog update and 1c60d1e for the workflow goal injection) were deployed.
  • Verification: The real proof was in the pudding. We verified the changes with workflow ddd599a1. The result? A 610-line implementation that covered the persona completion API, authentication middleware, streaming capabilities, prompt injection defense, a tRPC router, and even dashboard UI components. This isn't just "good enough"; it genuinely matches and, in some aspects, exceeds our hand-crafted gold standard.

Lessons Learned from the "Pain Log"

Every development session has its moments of frustration, but these are often where the most valuable lessons are forged.

Lesson 1: Explicit Goal Injection is Crucial for LLM Workflows

  • The Pain: Our AI was generating code for auxiliary systems (billing, security) instead of the core "rent-a-persona" API. The implementation prompt generator was only seeing isolated step outputs, not the overarching objective.
  • The Fix: Injecting a clear # FEATURE GOAL section at the very beginning of the prompt, synthesizing the workflow's name and description.
  • Actionable Takeaway: When building multi-step LLM-driven workflows, always ensure the final generation step has explicit, high-level context of the ultimate goal. Don't assume the LLM will infer it from intermediate outputs. Design your prompt structure to act as a guiding star.

Lesson 2: DevOps Hiccups Are Part of the Game

  • The Pain: During deployment, we encountered a docker container name conflict (2a8400fae69c_nyxcore-app-1 already in use).
  • The Fix: A quick docker rm -f <conflicting_container_id> followed by docker compose up -d app resolved it.
  • Actionable Takeaway: Keep your essential DevOps commands handy. Container conflicts are common, and knowing how to quickly force-remove and restart can save precious time during deployments.

Lesson 3: API Key Security is Paramount

  • The Pain: A user's Google API key was inadvertently exposed in chat during a debugging session.
  • The Fix: Immediately reminded the user to rotate their API key.
  • Actionable Takeaway: Always prioritize API key security. Educate users on best practices for environment variable management and regular key rotation. Provide direct links to key management portals (e.g., aistudio.google.com/apikey). A single exposure can compromise your entire system.

Current State & Next Steps

We're currently running on commit 1c60d1e in production, celebrating the successful injection of the workflow goal. Our implementation prompt provider order is robust: google (gemini-2.5-pro) leads, followed by openai (gpt-4o), kimi, and anthropic. We're leveraging a generous maxTokens: 16384 for the implementation prompt API call, with a MAX_TOTAL_CONTEXT: 60000 for input assembly, giving our models ample room to breathe and generate comprehensive outputs.

A minor note: our Anthropic credits are still depleted, meaning some auxiliary services like step digests, consistency checks, and hallucination detection are currently in a "fire-and-forget" state. This is a priority to address.

Looking ahead, here are our immediate next steps:

  1. API Key Rotation: The user should rotate their Google API key as a security best practice.
  2. Build with AI: We're seriously considering using the auto-generated implementation prompt from workflow ddd599a1 to actually build out the "rent-a-persona" feature. It's that good!
  3. Top Up Anthropic Credits: Restore full functionality for our consistency and detection services.
  4. Explore New Models: Evaluate adding newer models like gemini-3-pro-preview and gemini-3.1-pro-preview to our MODEL_CATALOG as they become available on our user's key.

This session was a powerful reminder that guiding LLMs effectively isn't just about crafting a single perfect prompt; it's about engineering the entire context and workflow to align with the ultimate objective. By explicitly injecting intent, we've moved a significant step closer to truly autonomous, production-grade code generation. The future of AI-assisted development is looking brighter than ever.

json
{"thingsDone":["Added gemini-2.5-pro to MODEL_CATALOG","Injected workflow goal into implementation prompt generator","Passed workflow name and description to prompt builder","Updated unit tests for workflowGoal field","Deployed two key commits","Verified workflow ddd599a1 producing 610 lines of complete code"],"pains":["Implementation prompt generated wrong feature (billing instead of persona API)","Root cause: prompt generator lacked workflow's high-level goal","Docker container name conflict during deploy","User's Google API key exposed in chat"],"successes":["Auto-generated output now matches/exceeds gold standard quality","Workflow goal injection successfully guided LLM to correct feature implementation","Resolved Docker conflict quickly","Reminded user about API key rotation and security"],"techStack":["TypeScript","Node.js","LLMs (Gemini, GPT-4o, Kimi, Anthropic)","Prompt Engineering","Docker","tRPC","Next.js (implied by UI/server structure)"]}