Skip to content

Feat/add middle out context strategy#141

Merged
gusye1234 merged 48 commits intomemodb-io:devfrom
riturajFi:feat/add_middle_out_context_strategy
Jan 14, 2026
Merged

Feat/add middle out context strategy#141
gusye1234 merged 48 commits intomemodb-io:devfrom
riturajFi:feat/add_middle_out_context_strategy

Conversation

@riturajFi
Copy link
Copy Markdown
Contributor

@riturajFi riturajFi commented Jan 13, 2026

Why we need this PR?

This should close Issue ()

Describe your solution

...

Implementation Tasks

Please ensure your pull request meets the following requirements:

  • PR Task 1
  • PR Task 2
  • ...

Impact Areas

Which part of Acontext would this feature affect?

  • Client SDK (Python)
  • Client SDK (TypeScript)
  • Core Service
  • API Server
  • Dashboard
  • CLI Tool
  • Documentation
  • Other: ...

Checklist

  • Open your pull request against the dev branch.
  • All tests pass in available continuous integration systems (e.g., GitHub Actions).
  • Tests are added or modified as needed to cover code changes.

Copy link
Copy Markdown
Contributor

@gusye1234 gusye1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

You can move the e2e scripts into one complete script, and place it in src/client/acontext-py/examples or src/client/acontext-ts/examples

We have CI/CD to run the script in those folder automatically.

return messages, nil
}
ctx := context.Background()
totalTokens, err := tokenizer.CountMessagePartsTokens(ctx, messages)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can count the exact token of each message? So in the later section, once we removed some messages, we can just reduce the total tokens.

instead of re-compute the tokens of the rest messages in every loop.

Comment on lines +86 to +107
for i, msg := range messages {
for _, part := range msg.Parts {
if part.Type == "tool-result" && part.Meta != nil {
if id, ok := part.Meta["tool_call_id"].(string); ok && id == toolCallID {
if _, ok := toRemove[i]; !ok {
toRemove[i] = struct{}{}
queue = append(queue, i)
}
break
}
}
}
}
for i, msg := range messages {
for _, part := range msg.Parts {
if part.Type == "tool-call" && part.Meta != nil {
if id, ok := part.Meta["id"].(string); ok && id == toolCallID {
if _, ok := toRemove[i]; !ok {
toRemove[i] = struct{}{}
queue = append(queue, i)
}
break
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate logic?? searches for tool-result twice

}
}
for totalTokens > s.TokenReduceTo && len(result) > 0 {
result = removeWithToolPairing(result, 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I am wrong but noo validation that first/last messages are not emoved this could break conversation context, no? @gusye1234

@riturajFi
Copy link
Copy Markdown
Contributor Author

Thanks @gusye1234 @slyt3 for your reviews. I shall polish these up asap. Excited to see first pr merge 😇

@riturajFi riturajFi force-pushed the feat/add_middle_out_context_strategy branch from 0e6ad20 to a70f617 Compare January 13, 2026 19:20
@riturajFi riturajFi requested review from gusye1234 and slyt3 January 13, 2026 19:23
Comment thread src/server/api/go/internal/pkg/editor/strategy_middle_out.go
@slyt3
Copy link
Copy Markdown
Contributor

slyt3 commented Jan 13, 2026

shouldnt it be this PR on dev branch? @gusye1234

@riturajFi riturajFi changed the base branch from main to dev January 13, 2026 21:56
@slyt3
Copy link
Copy Markdown
Contributor

slyt3 commented Jan 13, 2026

LGTM! Thanks for clarifying the intent in the fallback comment.

Copy link
Copy Markdown
Contributor

@gusye1234 gusye1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread src/server/api/go/internal/pkg/editor/strategy_middle_out.go
@riturajFi riturajFi force-pushed the feat/add_middle_out_context_strategy branch from ef7c051 to 15f4393 Compare January 14, 2026 12:55
@riturajFi riturajFi requested a review from gusye1234 January 14, 2026 12:56
@riturajFi
Copy link
Copy Markdown
Contributor Author

Hi @gusye1234
Addressed your concern here.
Kindly review

@gusye1234 gusye1234 merged commit 1c4ac53 into memodb-io:dev Jan 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants