@@ -23,8 +23,8 @@ func main() {
2323 {
2424 Name : "GetMeaningOfLife" ,
2525 Description : "Answer questions about meaning of life" ,
26- Body : func (ctx context.Context , _ []byte ) (any , error ) {
27- return 42 , nil
26+ Body : func (ctx context.Context , _ []byte ) (agency. Message , error ) {
27+ return agency . NewTextMessage ( agency . ToolRole , "42" ) , nil
2828 },
2929 },
3030 // function with parameters
@@ -38,12 +38,15 @@ func main() {
3838 "b" : {Type : "integer" },
3939 },
4040 },
41- Body : func (ctx context.Context , params []byte ) (any , error ) {
41+ Body : func (ctx context.Context , params []byte ) (agency. Message , error ) {
4242 var pp struct { A , B int }
4343 if err := json .Unmarshal (params , & pp ); err != nil {
4444 return nil , err
4545 }
46- return (pp .A + pp .B ) * 10 , nil // *10 is just to distinguish from normal response
46+ return agency .NewTextMessage (
47+ agency .ToolRole ,
48+ fmt .Sprintf ("%d" , (pp .A + pp .B )* 10 ),
49+ ), nil // *10 is just to distinguish from normal response
4750 },
4851 },
4952 },
@@ -64,30 +67,34 @@ Examples:
6467 // test for first function call
6568 answer , err := t2tOp .Execute (
6669 ctx ,
67- agency .UserMessage ( "what is the meaning of life?" ),
70+ agency .NewMessage ( agency . UserRole , agency . TextKind , [] byte ( "what is the meaning of life?" ) ),
6871 )
6972 if err != nil {
7073 panic (err )
7174 }
72- fmt . Println (answer )
75+ printAnswer (answer )
7376
7477 // test for second function call
7578 answer , err = t2tOp .Execute (
7679 ctx ,
77- agency .UserMessage ( "1+1?" ),
80+ agency .NewMessage ( agency . UserRole , agency . TextKind , [] byte ( "1+1?" ) ),
7881 )
7982 if err != nil {
8083 panic (err )
8184 }
82- fmt . Println (answer )
85+ printAnswer (answer )
8386
8487 // test for both function calls at the same time
8588 answer , err = t2tOp .Execute (
8689 ctx ,
87- agency .UserMessage ( "1+1 and what is the meaning of life?" ),
90+ agency .NewMessage ( agency . UserRole , agency . TextKind , [] byte ( "1+1 and what is the meaning of life?" ) ),
8891 )
8992 if err != nil {
9093 panic (err )
9194 }
92- fmt .Println (answer )
95+ printAnswer (answer )
96+ }
97+
98+ func printAnswer (message agency.Message ) {
99+ fmt .Printf ("Role: %s; Type: %s; Data: %s\n " , message .Role (), message .Kind (), agency .GetStringContent (message ))
93100}
0 commit comments