Skip to content
Notifications
Clear all

Help: The agent keeps losing context half-way through a complex function.

3 Posts
3 Users
0 Reactions
4 Views
(@jennak)
Trusted Member
Joined: 1 week ago
Posts: 37
Topic starter   [#11970]

I've been testing Codeium Chat for the past few weeks, specifically to help with refactoring some of our more complex Salesforce Apex classes. I'm hitting a consistent wall that's making it hard to rely on for larger tasks.

The issue happens when I ask it to analyze or rewrite a function that's, say, 80+ lines. It will start strong, giving a good breakdown of the logic and suggesting a solid plan. But about halfway through generating the actual refactored code, its suggestions seem to "forget" the earlier parts of the function or the specific requirements I outlined. It's like the context window gets filled and it starts working on the later part in isolation.

For example:
- I'll paste a function that handles a multi-step lead assignment process with several conditional branches and DML operations.
- Codeium will correctly identify the need to separate concerns (e.g., "extract the validation logic," "create a separate method for the DML").
- It begins writing the new validation method, but then when it moves to the core assignment logic, it omits a crucial check it had just mentioned seconds before.

Has anyone else run into this with longer, more integrated pieces of code? I'm trying to figure out if this is:
* A known limitation of the current context length.
* A prompt engineering issue on my part (should I be breaking the task into much smaller, separate prompts?).
* Just the nature of the tool for now, meaning it's better suited for smaller, discrete functions.

I'm comparing it to other assistants I use, and context retention on a single, complex task is a key differentiator for my workflow. Any insights or workarounds would be appreciated.


Benchmarks or bust


   
Quote
(@juliet)
Trusted Member
Joined: 1 week ago
Posts: 32
 

That's interesting, I've been looking at AI coding assistants too but mostly for smaller landing page scripts. Have you tried breaking the 80-line function into smaller chunks and feeding it to Codeium one piece at a time? Like, just the validation logic first? I wonder if that would help it keep focus.



   
ReplyQuote
(@davidm78)
Estimable Member
Joined: 6 days ago
Posts: 64
 

That's a smart approach to try. I've had some luck with that technique in Looker when working on massive derived tables - feeding the logic piece by piece can definitely keep things on track.

But with these refactoring tasks, I've found the tricky part is when the logic between those chunks is interdependent. If you break up a function with nested conditionals, the AI might optimize one piece in a way that breaks the flow for the next. Sometimes you end up spending more time stitching it back together than if you'd just written it yourself.

Have you tried that chunking method with any tools for Python or SQL, or just the front-end scripts?


Data doesn't lie, but dashboards sometimes do.


   
ReplyQuote