Skip to content

Commit f5ef0de

Browse files
committed
feat: Add submit task command to A2A CLI and update README with usage examples
Signed-off-by: Eden Reich <[email protected]>
1 parent cc16b6e commit f5ef0de

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

cli/cli.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func init() {
9393
tasksCmd.AddCommand(listTasksCmd)
9494
tasksCmd.AddCommand(getTaskCmd)
9595
tasksCmd.AddCommand(historyCmd)
96+
tasksCmd.AddCommand(submitTaskCmd)
9697

9798
rootCmd.AddCommand(configCmd)
9899
rootCmd.AddCommand(tasksCmd)
@@ -105,6 +106,7 @@ func init() {
105106
listTasksCmd.Flags().Int("limit", 50, "Maximum number of tasks to return")
106107
listTasksCmd.Flags().Int("offset", 0, "Number of tasks to skip")
107108
getTaskCmd.Flags().Int("history-length", 0, "Number of history messages to include")
109+
submitTaskCmd.Flags().String("context-id", "", "Context ID for the task (optional, will generate new context if not provided)")
108110
}
109111

110112
func initConfig() {
@@ -562,3 +564,63 @@ var versionCmd = &cobra.Command{
562564
fmt.Printf("Built: %s\n", buildDate)
563565
},
564566
}
567+
568+
var submitTaskCmd = &cobra.Command{
569+
Use: "submit [message]",
570+
Short: "Submit a new task to the A2A server",
571+
Long: "Submits a new task to the A2A server with the specified message.",
572+
Args: cobra.ExactArgs(1),
573+
RunE: func(cmd *cobra.Command, args []string) error {
574+
ctx := context.Background()
575+
ensureA2AClient()
576+
577+
message := args[0]
578+
contextID, _ := cmd.Flags().GetString("context-id")
579+
580+
messageID := fmt.Sprintf("msg-%d", time.Now().Unix())
581+
582+
params := adk.MessageSendParams{
583+
Message: adk.Message{
584+
Kind: "message",
585+
MessageID: messageID,
586+
Role: "user",
587+
Parts: []adk.Part{
588+
map[string]interface{}{
589+
"kind": "text",
590+
"text": message,
591+
},
592+
},
593+
},
594+
}
595+
596+
if contextID != "" {
597+
params.Message.ContextID = &contextID
598+
}
599+
600+
logger.Debug("Submitting new task", zap.String("message", message), zap.String("context_id", contextID))
601+
602+
resp, err := a2aClient.SendTask(ctx, params)
603+
if err != nil {
604+
return handleA2AError(err, "message/send")
605+
}
606+
607+
resultBytes, err := json.Marshal(resp.Result)
608+
if err != nil {
609+
return fmt.Errorf("failed to marshal response: %w", err)
610+
}
611+
612+
var task adk.Task
613+
if err := json.Unmarshal(resultBytes, &task); err != nil {
614+
return fmt.Errorf("failed to unmarshal task: %w", err)
615+
}
616+
617+
fmt.Printf("✅ Task submitted successfully!\n\n")
618+
fmt.Printf("Task Details:\n")
619+
fmt.Printf(" Task ID: %s\n", task.ID)
620+
fmt.Printf(" Context ID: %s\n", task.ContextID)
621+
fmt.Printf(" Status: %s\n", task.Status.State)
622+
fmt.Printf(" Message ID: %s\n", messageID)
623+
624+
return nil
625+
},
626+
}

example/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ docker compose run --rm a2a-debugger tasks list
4343
# List tasks with filtering
4444
docker compose run --rm a2a-debugger tasks list --state working --limit 10
4545

46+
# Submit a new task
47+
docker compose run --rm a2a-debugger tasks submit "Hello, can you help me?"
48+
49+
# Submit a task with a specific context ID
50+
docker compose run --rm a2a-debugger tasks submit "Continue our conversation" --context-id ctx-123
51+
4652
# Get detailed information about a specific task
4753
docker compose run --rm a2a-debugger tasks get <task-id>
4854

example/docker-compose.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ services:
33
image: ghcr.io/inference-gateway/google-calendar-agent:latest
44
pull_policy: always
55
environment:
6-
APP_DEMO_MODE: 'true'
6+
APP_DEMO_MODE: true
77
networks:
88
- a2a-network
99

1010
a2a-debugger:
11-
# image: ghcr.io/inference-gateway/a2a-debugger:latest
12-
# pull_policy: always
13-
build:
14-
context: ..
15-
dockerfile: Dockerfile
11+
image: ghcr.io/inference-gateway/a2a-debugger:latest
12+
pull_policy: always
1613
entrypoint:
1714
- /a2a
1815
- --config

0 commit comments

Comments
 (0)