Skip to content

Add Tool calls and tool Result in DB - #331

Open
sanskaraggarwal2025 wants to merge 28 commits into
mainfrom
tool-call-db
Open

sanskaraggarwal2025 wants to merge 28 commits into
mainfrom
tool-call-db

Conversation

@sanskaraggarwal2025

Copy link
Copy Markdown
Collaborator

No description provided.

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@sanskaraggarwal2025, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 56 minutes and 47 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 877a3ae3-e813-4920-bbdf-8096d91a6d9b

📥 Commits

Reviewing files that changed from the base of the PR and between 783f4a4 and 52c6eba.

⛔ Files ignored due to path filters (3)
  • backend/chatservice/proto/chatservice.pb.go is excluded by !**/*.pb.go
  • backend/chatservice/proto/chatservice_grpc.pb.go is excluded by !**/*.pb.go
  • backend/go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (27)
  • backend/chatservice/api/agent.go
  • backend/chatservice/dao/dao.go
  • backend/chatservice/dao/dao_postgres.go
  • backend/chatservice/dao/dao_sqlite.go
  • backend/chatservice/dao/dao_sqlite_test.go
  • backend/chatservice/dao/db/postgres/scripts/migrations/16_tool_usage.up.sql
  • backend/chatservice/dao/db/postgres/scripts/migrations/17_chat_message_tool_history.up.sql
  • backend/chatservice/dao/db/postgres/scripts/seed/2_add_support_tool_calling.up.sql
  • backend/chatservice/dao/db/sqlite/scripts/migrations/23_tool_usage.up.sql
  • backend/chatservice/dao/db/sqlite/scripts/migrations/24_chat_message_tool_history.up.sql
  • backend/chatservice/dao/db/sqlite/scripts/seed/2_add_support_tool_calling.up.sql
  • backend/chatservice/dao/models.go
  • backend/chatservice/service/agentic_chat.go
  • backend/chatservice/service/agentic_chat_tool.go
  • backend/chatservice/service/service.go
  • backend/chatservice/service/settings_service.go
  • backend/chatservice/sortedagents/agent_test.go
  • backend/chatservice/sortedagents/llm.go
  • backend/chatservice/sortedagents/runner.go
  • backend/chatservice/sortedagents/runner_test.go
  • backend/chatservice/sortedagents/session_test.go
  • backend/chatservice/sortedagents/test_build.go
  • docs/design decisions/WebSearch_tool.md
  • frontend/proto/chatservice.ts
  • frontend/src/pages/setting.tsx
  • frontend/src/store/setting.ts
  • proto/chatservice.proto
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tool-call-db

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces agentic chat functionality, enabling models to utilize tools such as Brave Search and Cloudflare-based web scraping. The implementation includes updates to the database schema and DAO layer to track tool usage and costs, a new agentic service layer, and frontend configuration options. Review feedback identified several improvement opportunities, including making rate-limit sleep durations context-aware, implementing more robust detection for structured message content, and adopting safer URL construction practices for API requests.

var waitSeconds int
fmt.Sscanf(retryAfter, "%d", &waitSeconds)
if waitSeconds > 0 && waitSeconds <= 60 { // Max 60 seconds wait
time.Sleep(time.Duration(waitSeconds) * time.Second)

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.

high

time.Sleep is not context-aware. If the request context is cancelled while the tool is sleeping during a rate-limit backoff, it will continue to block the goroutine until the sleep duration expires. Use a select statement with ctx.Done() and time.After() instead.

select {
case <-ctx.Done():
    return nil, ctx.Err()
case <-time.After(time.Duration(waitSeconds) * time.Second):
}

Comment on lines +115 to +120
if strings.HasPrefix(msg.Content, "[") && strings.HasSuffix(msg.Content, "]") {
var textContents []*pb.MessageContent
if err := json.Unmarshal([]byte(msg.Content), &textContents); err != nil {
return nil, fmt.Errorf("failed to parse text content: %w", err)
}
contents = append(contents, textContents...)

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.

medium

The check for JSON content in msg.Content is fragile. If a user sends a message that happens to start with [ and end with ], json.Unmarshal will be attempted and might fail, causing the entire agentic session build to error out. Consider a more robust way to distinguish between raw text and structured message content, perhaps by checking the msg.Type or using a specific prefix.

return nil, fmt.Errorf("query parameter is required")
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, t.apiURL+"?q="+url.QueryEscape(query), nil)

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.

medium

Constructing the URL by simple string concatenation is risky if t.apiURL already contains query parameters. It is safer to use url.Parse and url.Values to manage query parameters.

Suggested change
req, err := http.NewRequestWithContext(ctx, http.MethodGet, t.apiURL+"?q="+url.QueryEscape(query), nil)
u, err := url.Parse(t.apiURL)
if err != nil {
return nil, fmt.Errorf("failed to parse api url: %w", err)
}
q := u.Query()
q.Set("q", query)
u.RawQuery = q.Encode()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)

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.

1 participant