flightbooking

package
v1.45.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Intermediate

type Intermediate struct {
	*connector.Connector
	ToDo
}

Intermediate extends and customizes the generic base connector.

func NewIntermediate

func NewIntermediate(impl ToDo) *Intermediate

NewIntermediate creates a new instance of the intermediate.

type Mock

type Mock struct {
	*Intermediate
	// contains filtered or unexported fields
}

Mock is a mockable version of the microservice, allowing functions, event sinks and web handlers to be mocked.

func NewMock

func NewMock() *Mock

NewMock creates a new mockable version of the microservice.

func (*Mock) AwaitDecision

func (svc *Mock) AwaitDecision(ctx context.Context, flow *workflow.Flow, currentFlight flightbookingapi.Flight, flightIndex int) (accepted bool, flightIndexOut int, err error)

AwaitDecision executes the mock handler.

func (*Mock) BookFlight

func (svc *Mock) BookFlight(ctx context.Context) (graph *workflow.Graph, err error)

BookFlight returns the workflow graph, or a mocked graph if MockBookFlight was called.

func (*Mock) ChooseSeat

func (svc *Mock) ChooseSeat(ctx context.Context, flow *workflow.Flow, seatPreference string, currentFlight flightbookingapi.Flight) (seat string, err error)

ChooseSeat executes the mock handler.

func (*Mock) ChooseSeatAgent

func (svc *Mock) ChooseSeatAgent(ctx context.Context) (graph *workflow.Graph, err error)

ChooseSeatAgent returns the workflow graph, or a mocked graph if MockChooseSeatAgent was called.

func (*Mock) ConfirmBooking

func (svc *Mock) ConfirmBooking(ctx context.Context, flow *workflow.Flow, currentFlight flightbookingapi.Flight, seat string) (confirmation string, airline string, flightNo string, err error)

ConfirmBooking executes the mock handler.

func (*Mock) Demo

func (svc *Mock) Demo(w http.ResponseWriter, r *http.Request) (err error)

Demo executes the mock handler.

func (*Mock) MockAwaitDecision

func (svc *Mock) MockAwaitDecision(handler func(ctx context.Context, flow *workflow.Flow, currentFlight flightbookingapi.Flight, flightIndex int) (accepted bool, flightIndexOut int, err error)) *Mock

MockAwaitDecision sets up a mock handler for AwaitDecision.

func (*Mock) MockBookFlight

func (svc *Mock) MockBookFlight(handler func(ctx context.Context, flow *workflow.Flow, origin string, destination string, seatPreference string) (confirmation string, airline string, flightNo string, seat string, err error)) *Mock

MockBookFlight sets up a mock handler for the BookFlight workflow. The handler receives typed inputs from the workflow's state and returns typed outputs. A nil handler clears the mock.

func (*Mock) MockChooseSeat

func (svc *Mock) MockChooseSeat(handler func(ctx context.Context, flow *workflow.Flow, seatPreference string, currentFlight flightbookingapi.Flight) (seat string, err error)) *Mock

MockChooseSeat sets up a mock handler for ChooseSeat.

func (*Mock) MockChooseSeatAgent

func (svc *Mock) MockChooseSeatAgent(handler func(ctx context.Context, flow *workflow.Flow, seatPreference string, availableSeats []string) (seat string, err error)) *Mock

MockChooseSeatAgent sets up a mock handler for the ChooseSeatAgent workflow. The handler receives typed inputs from the workflow's state and returns typed outputs. A nil handler clears the mock.

func (*Mock) MockConfirmBooking

func (svc *Mock) MockConfirmBooking(handler func(ctx context.Context, flow *workflow.Flow, currentFlight flightbookingapi.Flight, seat string) (confirmation string, airline string, flightNo string, err error)) *Mock

MockConfirmBooking sets up a mock handler for ConfirmBooking.

func (*Mock) MockDemo

func (svc *Mock) MockDemo(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock

MockDemo sets up a mock handler for Demo.

func (*Mock) MockNoFlights

func (svc *Mock) MockNoFlights(handler func(ctx context.Context, flow *workflow.Flow) (confirmation string, err error)) *Mock

MockNoFlights sets up a mock handler for NoFlights.

func (*Mock) MockPickSeat

func (svc *Mock) MockPickSeat(handler func(ctx context.Context, flow *workflow.Flow, seatPreference string, availableSeats []string) (seat string, err error)) *Mock

MockPickSeat sets up a mock handler for PickSeat.

func (*Mock) MockProposeFlight

func (svc *Mock) MockProposeFlight(handler func(ctx context.Context, flow *workflow.Flow, candidates []flightbookingapi.Flight, flightIndex int) (currentFlight flightbookingapi.Flight, exhausted bool, err error)) *Mock

MockProposeFlight sets up a mock handler for ProposeFlight.

func (*Mock) MockSearchFlights

func (svc *Mock) MockSearchFlights(handler func(ctx context.Context, flow *workflow.Flow, origin string, destination string) (candidates []flightbookingapi.Flight, flightIndex int, err error)) *Mock

MockSearchFlights sets up a mock handler for SearchFlights.

func (*Mock) NoFlights

func (svc *Mock) NoFlights(ctx context.Context, flow *workflow.Flow) (confirmation string, err error)

NoFlights executes the mock handler.

func (*Mock) OnShutdown

func (svc *Mock) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Mock) OnStartup

func (svc *Mock) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Mock) PickSeat

func (svc *Mock) PickSeat(ctx context.Context, flow *workflow.Flow, seatPreference string, availableSeats []string) (seat string, err error)

PickSeat executes the mock handler.

func (*Mock) ProposeFlight

func (svc *Mock) ProposeFlight(ctx context.Context, flow *workflow.Flow, candidates []flightbookingapi.Flight, flightIndex int) (currentFlight flightbookingapi.Flight, exhausted bool, err error)

ProposeFlight executes the mock handler.

func (*Mock) SearchFlights

func (svc *Mock) SearchFlights(ctx context.Context, flow *workflow.Flow, origin string, destination string) (candidates []flightbookingapi.Flight, flightIndex int, err error)

SearchFlights executes the mock handler.

type Service

type Service struct {
	*Intermediate // IMPORTANT: Do not remove

}

Service implements the flightbooking.example agent. It runs a durable BookFlight workflow that searches a route, proposes candidate flights one at a time, parks on a human accept/keep-searching decision, and on acceptance delegates seat selection to a child LLM workflow before confirming the booking.

func NewService

func NewService() *Service

NewService creates a new instance of the microservice.

func (*Service) AwaitDecision

func (svc *Service) AwaitDecision(ctx context.Context, flow *workflow.Flow, currentFlight flightbookingapi.Flight, flightIndex int) (accepted bool, flightIndexOut int, err error)

AwaitDecision parks the flow on a human accept/keep-searching decision for the proposed flight and advances to the next candidate when the traveler keeps searching.

func (*Service) BookFlight

func (svc *Service) BookFlight(ctx context.Context) (graph *workflow.Graph, err error)

BookFlight is the top-level agentic workflow. It searches the route, then loops proposing one candidate flight at a time and parking on a human accept/keep-searching decision via Interrupt. On acceptance it invokes the ChooseSeatAgent child workflow as an isolated subgraph to pick a seat, then confirms the booking.

func (*Service) ChooseSeat

func (svc *Service) ChooseSeat(ctx context.Context, flow *workflow.Flow, seatPreference string, currentFlight flightbookingapi.Flight) (seat string, err error)

ChooseSeat delegates seat selection for the accepted flight to the ChooseSeatAgent child workflow.

func (*Service) ChooseSeatAgent

func (svc *Service) ChooseSeatAgent(ctx context.Context) (graph *workflow.Graph, err error)

ChooseSeatAgent is a child workflow that selects a single seat from a flight's available seats to match a natural-language preference. It is invoked as an isolated subgraph by the BookFlight workflow's ChooseSeat task.

func (*Service) ConfirmBooking

func (svc *Service) ConfirmBooking(ctx context.Context, flow *workflow.Flow, currentFlight flightbookingapi.Flight, seat string) (confirmation string, airline string, flightNo string, err error)

ConfirmBooking finalizes the booking of the accepted flight and chosen seat into a confirmation.

func (*Service) Demo

func (svc *Service) Demo(w http.ResponseWriter, r *http.Request) (err error)

Demo serves the human-in-the-loop demo page that drives the BookFlight workflow, presenting each proposed flight and resuming the parked flow with the traveler's accept or keep-searching decision.

func (*Service) Init

func (svc *Service) Init(initializer func(svc *Service) (err error)) *Service

Init enables a single-statement pattern for initializing the microservice.

func (*Service) NoFlights

func (svc *Service) NoFlights(ctx context.Context, flow *workflow.Flow) (confirmation string, err error)

NoFlights ends the workflow with a not-booked message when no flight is available or every candidate is declined.

func (*Service) OnShutdown

func (svc *Service) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Service) OnStartup

func (svc *Service) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Service) PickSeat

func (svc *Service) PickSeat(ctx context.Context, flow *workflow.Flow, seatPreference string, availableSeats []string) (seat string, err error)

PickSeat asks the LLM to choose one seat from the available list that best matches the traveler's preference.

func (*Service) ProposeFlight

func (svc *Service) ProposeFlight(ctx context.Context, flow *workflow.Flow, candidates []flightbookingapi.Flight, flightIndex int) (currentFlight flightbookingapi.Flight, exhausted bool, err error)

ProposeFlight selects the candidate at the current index, or marks the search exhausted when the list runs out.

func (*Service) SearchFlights

func (svc *Service) SearchFlights(ctx context.Context, flow *workflow.Flow, origin string, destination string) (candidates []flightbookingapi.Flight, flightIndex int, err error)

SearchFlights looks up the flights serving a route and seeds the candidate list for the workflow to propose.

type ToDo

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	Demo(w http.ResponseWriter, r *http.Request) (err error)                                                                                                                          // MARKER: Demo
	SearchFlights(ctx context.Context, flow *workflow.Flow, origin string, destination string) (candidates []flightbookingapi.Flight, flightIndex int, err error)                     // MARKER: SearchFlights
	ProposeFlight(ctx context.Context, flow *workflow.Flow, candidates []flightbookingapi.Flight, flightIndex int) (currentFlight flightbookingapi.Flight, exhausted bool, err error) // MARKER: ProposeFlight
	AwaitDecision(ctx context.Context, flow *workflow.Flow, currentFlight flightbookingapi.Flight, flightIndex int) (accepted bool, flightIndexOut int, err error)                    // MARKER: AwaitDecision
	ChooseSeat(ctx context.Context, flow *workflow.Flow, seatPreference string, currentFlight flightbookingapi.Flight) (seat string, err error)                                       // MARKER: ChooseSeat
	ConfirmBooking(ctx context.Context, flow *workflow.Flow, currentFlight flightbookingapi.Flight, seat string) (confirmation string, airline string, flightNo string, err error)    // MARKER: ConfirmBooking
	NoFlights(ctx context.Context, flow *workflow.Flow) (confirmation string, err error)                                                                                              // MARKER: NoFlights
	PickSeat(ctx context.Context, flow *workflow.Flow, seatPreference string, availableSeats []string) (seat string, err error)                                                       // MARKER: PickSeat
	BookFlight(ctx context.Context) (graph *workflow.Graph, err error)                                                                                                                // MARKER: BookFlight
	ChooseSeatAgent(ctx context.Context) (graph *workflow.Graph, err error)                                                                                                           // MARKER: ChooseSeatAgent
}

ToDo is implemented by the service or mock. The intermediate delegates handling to this interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL