Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions agenticrtbframeworkservices.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package com.iabtechlab.bidstream.mutation.services.v1;

option go_package = "github.com/iabtechlab/agentic-rtb-framework/pkg/pb/artf";

import "agenticrtbframework.proto";

service RTBExtensionPoint {
Expand Down
5 changes: 1 addition & 4 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ func (a *ARTFAgent) GetMutations(ctx context.Context, req *pb.RTBRequest) (*pb.R
bidRequest := req.GetBidRequest()
bidResponse := req.GetBidResponse()

// NOTE: applicable_intents is defined in the proto spec but not yet in the generated Go code.
// After regenerating protos with `make bindings`, use: applicableIntents := req.GetApplicableIntents()
// For now, pass nil which means all intents are applicable.
var applicableIntents []pb.Intent
applicableIntents := req.GetApplicableIntents()

log.Printf("Processing request %s at lifecycle stage %v with applicable_intents=%v",
req.GetId(), lifecycle, applicableIntents)
Expand Down
3 changes: 2 additions & 1 deletion internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package handlers
import (
"context"
"log"
"time"

pb "github.com/iabtechlab/agentic-rtb-framework/pkg/pb/artf"
openrtb "github.com/iabtechlab/agentic-rtb-framework/pkg/pb/openrtb"
Expand Down Expand Up @@ -211,7 +212,7 @@ func determineUserSegments(user *openrtb.BidRequest_User) []string {

// Example: Add demographic segments based on user attributes
if user.GetYob() > 0 {
age := 2024 - int(user.GetYob())
age := time.Now().Year() - int(user.GetYob())
if age >= 18 && age <= 24 {
segments = append(segments, "demo-18-24")
} else if age >= 25 && age <= 34 {
Expand Down
63 changes: 51 additions & 12 deletions internal/mcp/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,38 @@ func (a *Agent) handleExtendRTB(ctx context.Context, request mcp.CallToolRequest
bidResponseRaw = br
}

// Get optional lifecycle (NOTE: Full lifecycle enum requires proto regeneration)
// Get optional lifecycle
var lifecycleStr string
if lc, ok := args["lifecycle"].(string); ok && lc != "" {
lifecycleStr = lc
}
lifecycle := pb.Lifecycle_LIFECYCLE_UNSPECIFIED
lifecycle := parseLifecycle(lifecycleStr)

// Get optional originator (NOTE: Originator type requires proto regeneration)
// Get optional originator
var originator *pb.Originator
var originatorStr string
if orig, ok := args["originator"].(map[string]interface{}); ok {
originator = &pb.Originator{}
if t, ok := orig["type"].(string); ok {
originatorStr = t
originatorType := parseOriginatorType(t)
originator.Type = originatorType.Enum()
}
if id, ok := orig["id"].(string); ok {
originator.Id = &id
}
}

// Get optional applicable_intents
var applicableIntentStrs []string
var applicableIntents []pb.Intent
if intentsRaw, ok := args["applicable_intents"].([]interface{}); ok {
for _, intentRaw := range intentsRaw {
if intentStr, ok := intentRaw.(string); ok {
applicableIntentStrs = append(applicableIntentStrs, intentStr)
if parsed := parseIntent(intentStr); parsed != pb.Intent_INTENT_UNSPECIFIED {
applicableIntents = append(applicableIntents, parsed)
}
}
}
}
Expand All @@ -203,13 +214,14 @@ func (a *Agent) handleExtendRTB(ctx context.Context, request mcp.CallToolRequest
}

// Build the gRPC request
// NOTE: applicable_intents, originator, and full lifecycle enum require proto regeneration.
grpcRequest := &pb.RTBRequest{
Id: &id,
Tmax: &tmax,
Lifecycle: lifecycle.Enum(),
BidRequest: bidRequest,
BidResponse: bidResponse,
Id: &id,
Tmax: &tmax,
Lifecycle: lifecycle.Enum(),
BidRequest: bidRequest,
BidResponse: bidResponse,
Originator: originator,
ApplicableIntents: applicableIntents,
}

// Call the gRPC agent directly (no network hop)
Expand Down Expand Up @@ -317,8 +329,6 @@ func (a *Agent) handleListFederatedEndpoints(ctx context.Context, request mcp.Ca
}

// parseIntent converts a string to pb.Intent
// NOTE: After proto regeneration, add parseLifecycle, parseOriginatorType functions
// and ADD_CIDS case to this switch
func parseIntent(s string) pb.Intent {
switch s {
case "ACTIVATE_SEGMENTS":
Expand All @@ -335,12 +345,41 @@ func parseIntent(s string) pb.Intent {
return pb.Intent_BID_SHADE
case "ADD_METRICS":
return pb.Intent_ADD_METRICS
// case "ADD_CIDS": return pb.Intent_ADD_CIDS // Requires proto regeneration
case "ADD_CIDS":
return pb.Intent_ADD_CIDS
default:
return pb.Intent_INTENT_UNSPECIFIED
}
}

// parseLifecycle converts a string to pb.Lifecycle
func parseLifecycle(s string) pb.Lifecycle {
switch s {
case "LIFECYCLE_PUBLISHER_BID_REQUEST":
return pb.Lifecycle_LIFECYCLE_PUBLISHER_BID_REQUEST
case "LIFECYCLE_DSP_BID_RESPONSE":
return pb.Lifecycle_LIFECYCLE_DSP_BID_RESPONSE
default:
return pb.Lifecycle_LIFECYCLE_UNSPECIFIED
}
}

// parseOriginatorType converts a string to pb.Originator_Type
func parseOriginatorType(s string) pb.Originator_Type {
switch s {
case "TYPE_PUBLISHER":
return pb.Originator_TYPE_PUBLISHER
case "TYPE_SSP":
return pb.Originator_TYPE_SSP
case "TYPE_EXCHANGE":
return pb.Originator_TYPE_EXCHANGE
case "TYPE_DSP":
return pb.Originator_TYPE_DSP
default:
return pb.Originator_TYPE_UNSPECIFIED
}
}

// jsonToOpenRTBBidRequest converts JSON map to OpenRTB BidRequest protobuf
func jsonToOpenRTBBidRequest(data map[string]interface{}) (*openrtb.BidRequest, error) {
jsonBytes, err := json.Marshal(data)
Expand Down
Loading