Skip to content

Add GetMetadata() method to TaskHandler interface to allow for propagating metadata to processors #67

@kieranbarty

Description

@kieranbarty

We want to be able to use optional, client defined fields for things like trackingID through our entire agent lifecycle.

Currently we can achieve this by adding context values based on user inputs, but we would like to avoid bloating the context for a given request. We could achieve this by allowing us to store the metadata on the TaskHandler itself, and we could then retrieve it as/when we need to when we process a message. I'm happy to contribute this change as well :)

Heres an example of how I think we could do this:

TaskManager.go

handle := &taskHandler{
	taskManager:       t,
	metadata: request.Metadata,
	messageId:         request.Message.MessageID,
	ctx:               ctx,
}
TaskHandler.go

type taskHandler struct {
	taskManager           *TaskManager
	messageId             string
	metadata              map[string]any
	ctx                   context.Context
}

// Optionally we can pass a key into this method, and return single values.
func (t taskHandler) GetMetadata() (map[string]any, error) {
	if t.metadata == nil {
		return nil, errors.New("metadata is nil")
	}

	return t.metadata, nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions